Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vsp over object v3 mc #245

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
01c6cc6
Added createUser operation to replace setUUIDMetadata
marcin-cebo Aug 26, 2022
97d8187
Added removeUser operation to replace removeUUIDMetadata
marcin-cebo Aug 29, 2022
54ad64d
Added fetchUser operation to replace getUUIDMetadata
marcin-cebo Aug 29, 2022
8bbdb29
Added updateUser operation to replace setUUIDMetadata
marcin-cebo Aug 31, 2022
eaddbf3
Added upsertUser operation to replace setUUIDMetadata
marcin-cebo Sep 1, 2022
80173e7
Added upsertUser operation to replace setUUIDMetadata
marcin-cebo Sep 1, 2022
447a47c
Added createSpace operation to replace setChannelMetadata
marcin-cebo Sep 2, 2022
606f364
Added removeSpace operation to replace removeChannelMetadata
marcin-cebo Sep 2, 2022
e0baae7
Added removeSpace operation to replace removeChannelMetadata
marcin-cebo Sep 2, 2022
1913dd4
Added fetchSpace operation to replace getChannelMetadata
marcin-cebo Sep 5, 2022
9420144
Added updateSpace operation to replace setChannelMetadata
marcin-cebo Sep 5, 2022
048ba17
Added upsertSpace operation to replace setChannelMetadata
marcin-cebo Sep 5, 2022
88f9b92
Added upsertSpace operation to replace setChannelMetadata
marcin-cebo Sep 5, 2022
7ac0e9f
ObjectV3 user/space changes after code review.
marcin-cebo Sep 8, 2022
4285deb
ObjectV3 user/space changes after code review.
marcin-cebo Sep 9, 2022
7d9852e
ObjectV3 user/space changes after code review.
marcin-cebo Sep 9, 2022
ba24d8d
ObjectV3 user/space changes after code review.
marcin-cebo Sep 9, 2022
1fede60
ObjectV3 user/space changes after code review.
marcin-cebo Sep 12, 2022
a7e1969
ObjectV3 user/space changes after code review.
marcin-cebo Sep 13, 2022
30339ac
Revert "ObjectV3 user/space changes after code review."
marcin-cebo Sep 13, 2022
8c7a637
ObjectV3 user/space changes after code review.
marcin-cebo Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
import com.pubnub.api.enums.PNLogVerbosity;
import com.pubnub.api.integration.util.ITTestConfig;
import org.aeonbits.owner.ConfigFactory;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;

import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assume.assumeThat;

public abstract class ObjectsApiBaseIT {
//See README.md in integrationTest directory for more info on running integration tests
private ITTestConfig itTestConfig = ConfigFactory.create(ITTestConfig.class, System.getenv());
public static final String STATUS_ACTIVE = "Active";
public static final String TYPE_HUMAN = "Human";

protected final PubNub pubNubUnderTest = pubNub();

Expand All @@ -35,4 +41,39 @@ private PubNub pubNub() {
public void assumeTestsAreConfiguredProperly() {
assumeThat("Subscription key must be set in test.properties", itTestConfig.subscribeKey(), not(isEmptyOrNullString()));
}

protected String randomName() {
return RandomStringUtils.randomAlphabetic(5, 10) + " " + RandomStringUtils.randomAlphabetic(5, 10);
}

protected Map<String, Object> customUserObject() {
return getCustomObject();
}

protected Map<String, Object> customSpaceObject() {
return getCustomObject();
}

private Map<String, Object> getCustomObject(){
final Map<String, Object> customMap = new HashMap<>();
customMap.putIfAbsent("param1", "val1");
customMap.putIfAbsent("param2", "val2");
return customMap;
}

protected Map<String, Object> updatedCustomUserObject() {
return updatedCustomObject();
}

protected Map<String, Object> updatedCustomSpaceObject() {
return updatedCustomObject();
}

private Map<String, Object> updatedCustomObject() {
final Map<String, Object> customMap = new HashMap<>();
customMap.putIfAbsent("param1", "val1_updated");
customMap.putIfAbsent("param2", "val2_updated");
customMap.putIfAbsent("param3", "added");
return customMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ private String randomEmail() {
return RandomStringUtils.randomAlphabetic(6) + "@example.com";
}

private String randomName() {
return RandomStringUtils.randomAlphabetic(5, 10) + " " + RandomStringUtils.randomAlphabetic(5, 10);
}

private String randomProfileUrl() {
return "http://" + RandomStringUtils.randomAlphabetic(5, 15) + ".com";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
package com.pubnub.api.integration.objects_vsp.space;

import com.google.gson.JsonObject;
import com.pubnub.api.PubNubException;
import com.pubnub.api.SpaceId;
import com.pubnub.api.integration.objects.ObjectsApiBaseIT;
import com.pubnub.api.models.consumer.objects_vsp.space.RemoveSpaceResult;
import com.pubnub.api.models.consumer.objects_vsp.space.Space;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.Map;
import java.util.Random;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class SpaceIT extends ObjectsApiBaseIT {

private final String randomSpaceIdValue = getRandomSpaceIdValue();
private SpaceId randomSpaceId;
private final String randomName = randomName();
private final String randomDescription = randomDescription();

@Before
public void setUp() throws Exception {
randomSpaceId = new SpaceId(randomSpaceIdValue);
}

@Test
public void createUserHappyPath() throws PubNubException {
//given

//when
Space space = pubNubUnderTest.createSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//then
assertNotNull(space);
assertEquals(randomSpaceIdValue, space.getId());
assertEquals(randomName, space.getName());
assertEquals(randomDescription, space.getDescription());
assertNotNull(space.getCustom());
assertEquals(STATUS_ACTIVE, space.getStatus());
assertEquals(TYPE_HUMAN, space.getType());
}

@Test(expected = PubNubException.class)
public void should_throw_exception_when_space_with_the_spaceId_exists() throws PubNubException {
//given
pubNubUnderTest.createSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//when
pubNubUnderTest.createSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//then
}

@Test
public void removeSpaceHappyPath() throws PubNubException {
//given
pubNubUnderTest.createSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//when
RemoveSpaceResult removeSpaceResult = pubNubUnderTest.removeSpace(randomSpaceId).sync();

//then
assertEquals(HttpStatus.SC_OK, removeSpaceResult.getStatus());


}

@Test
public void fetchSpaceHappyPath() throws PubNubException {
//given
pubNubUnderTest.createSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//when
Space space = pubNubUnderTest.fetchSpace(randomSpaceId)
.sync();

//then
assertNotNull(space);
assertEquals(randomSpaceIdValue, space.getId());
assertEquals(randomName, space.getName());
assertEquals(randomDescription, space.getDescription());
assertNotNull(space.getCustom());
assertEquals(STATUS_ACTIVE, space.getStatus());
assertEquals(TYPE_HUMAN, space.getType());

}

@Test
public void updateSpace_passing_full_object_happyPath() throws PubNubException {
//given
String updatedName = "updatedName" + randomName();
String updatedDescription = "updatedDescription" + randomName();
Map<String, Object> updateCustom = updatedCustomSpaceObject();
String updatedStatus = "updatedStatus" + STATUS_ACTIVE;
String updatedType = "updatedType" + TYPE_HUMAN;

pubNubUnderTest.createSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//when
Space updatedSpace = pubNubUnderTest.updateSpace(randomSpaceId)
.name(updatedName)
.description(updatedDescription)
.custom(updateCustom)
.status(updatedStatus)
.type(updatedType)
.sync();

//then
assertNotNull(updatedSpace);
assertEquals(randomSpaceIdValue, updatedSpace.getId());
assertEquals(updatedName, updatedSpace.getName());
assertEquals(updatedDescription, updatedSpace.getDescription());
assertEquals(updatedDescription, updatedSpace.getDescription());
assertEquals("\"val1_updated\"", ((JsonObject) updatedSpace.getCustom()).getAsJsonObject().get("param1").toString());
assertEquals("\"val2_updated\"", ((JsonObject) updatedSpace.getCustom()).getAsJsonObject().get("param2").toString());
assertEquals("\"added\"", ((JsonObject) updatedSpace.getCustom()).getAsJsonObject().get("param3").toString());
assertEquals(updatedStatus, updatedSpace.getStatus());
assertEquals(updatedType, updatedSpace.getType());

Space space = pubNubUnderTest.fetchSpace(randomSpaceId)
.sync();

assertNotNull(space);
assertEquals(randomSpaceIdValue, space.getId());
assertEquals(updatedName, space.getName());
assertEquals(updatedDescription, space.getDescription());
assertNotNull(space.getCustom());
assertEquals(updatedStatus, space.getStatus());
assertEquals(updatedType, space.getType());
}

@Test(expected = PubNubException.class)
public void updateSpace_should_throw_exception_when_updating_space_that_does_not_exist() throws PubNubException {
//given
String updatedName = "updatedName" + randomName();

//when
pubNubUnderTest.updateSpace(randomSpaceId)
.name(updatedName)
.sync();

//then

}

@Test
public void upsertSpaceHappyPath_newSpaceCreated() throws PubNubException {
//given

//when
Space space = pubNubUnderTest.upsertSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//then
assertNotNull(space);
assertEquals(randomSpaceIdValue, space.getId());
assertEquals(randomName, space.getName());
assertEquals(randomDescription, space.getDescription());
assertNotNull(space.getCustom());
assertEquals(STATUS_ACTIVE, space.getStatus());
assertEquals(TYPE_HUMAN, space.getType());
}

@Test
public void upsertSpaceHappyPath_existingSpaceUpdated() throws PubNubException {
//given
String updatedName = "updatedName" + randomName();
String updatedDescription = "updatedDescription" + randomName();
Map<String, Object> updateCustom = updatedCustomSpaceObject();
String updatedStatus = "updatedStatus" + STATUS_ACTIVE;
String updatedType = "updatedType" + TYPE_HUMAN;

pubNubUnderTest.createSpace(randomSpaceId)
.name(randomName)
.description(randomDescription)
.custom(customSpaceObject())
.includeCustom(true)
.status(STATUS_ACTIVE)
.type(TYPE_HUMAN)
.sync();

//when
Space spaceAfterUpsert = pubNubUnderTest.upsertSpace(randomSpaceId)
.name(updatedName)
.description(updatedDescription)
.custom(updateCustom)
.status(updatedStatus)
.type(updatedType)
.sync();

//then
assertNotNull(spaceAfterUpsert);
assertEquals(randomSpaceIdValue, spaceAfterUpsert.getId());
assertEquals(updatedName, spaceAfterUpsert.getName());
assertEquals(updatedDescription, spaceAfterUpsert.getDescription());
assertEquals(updatedDescription, spaceAfterUpsert.getDescription());
assertEquals("\"val1_updated\"", ((JsonObject) spaceAfterUpsert.getCustom()).getAsJsonObject().get("param1").toString());
assertEquals("\"val2_updated\"", ((JsonObject) spaceAfterUpsert.getCustom()).getAsJsonObject().get("param2").toString());
assertEquals("\"added\"", ((JsonObject) spaceAfterUpsert.getCustom()).getAsJsonObject().get("param3").toString());
assertEquals(updatedStatus, spaceAfterUpsert.getStatus());
assertEquals(updatedType, spaceAfterUpsert.getType());

Space space = pubNubUnderTest.fetchSpace(randomSpaceId)
.sync();

assertNotNull(space);
assertEquals(randomSpaceIdValue, space.getId());
assertEquals(updatedName, space.getName());
assertEquals(updatedDescription, space.getDescription());
assertNotNull(space.getCustom());
assertEquals(updatedStatus, space.getStatus());
assertEquals(updatedType, space.getType());
}

@After
public void tearDown() throws Exception {
pubNubUnderTest.removeSpace(randomSpaceId).sync();
}

private String getRandomSpaceIdValue() {
return "spaceId" + new Random().nextInt(100000);
}

private static String randomDescription() {
return RandomStringUtils.randomAlphabetic(50, 160);
}
}
Loading