use of org.sagebionetworks.bridge.models.appconfig.ConfigResolver in project BridgeServer2 by Sage-Bionetworks.
the class TestUtils method mockConfigResolver.
public static ConfigResolver mockConfigResolver(Environment env, String subdomain) {
BridgeConfig mockConfig = Mockito.mock(BridgeConfig.class);
when(mockConfig.getEnvironment()).thenReturn(env);
when(mockConfig.getHostnameWithPostfix(subdomain)).thenReturn(subdomain + "-" + env.name().toLowerCase() + ".bridge.org");
return new ConfigResolver(mockConfig);
}
use of org.sagebionetworks.bridge.models.appconfig.ConfigResolver in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentInfoTest method canSerialize.
@Test
public void canSerialize() throws Exception {
ConfigResolver resolver = ConfigResolver.INSTANCE;
String url = resolver.url("ws", "/v1/assessments/guid/config");
AssessmentReference ref = new AssessmentReference();
ref.setGuid("guid");
ref.setAppId(TEST_APP_ID);
ref.setIdentifier("identifier");
ref.setRevision(5);
ref.setTitle("title");
ref.setLabels(ImmutableList.of(new Label("en", "English"), new Label("de", "German")));
ref.setMinutesToComplete(10);
ref.setColorScheme(new ColorScheme("#111111", "#222222", "#333333", "#444444"));
AssessmentInfo info = AssessmentInfo.create(ref);
JsonNode node = BridgeObjectMapper.get().valueToTree(info);
assertEquals(node.get("guid").textValue(), "guid");
assertEquals(node.get("appId").textValue(), TEST_APP_ID);
assertEquals(node.get("identifier").textValue(), "identifier");
assertEquals(node.get("revision").intValue(), 5);
assertEquals(node.get("label").textValue(), "English");
assertEquals(node.get("minutesToComplete").intValue(), 10);
assertEquals(node.get("key").textValue(), "b380003bb380003b");
assertEquals(node.get("configUrl").textValue(), url);
assertEquals(node.get("type").textValue(), "AssessmentInfo");
assertEquals(node.get("colorScheme").get("background").textValue(), "#111111");
assertEquals(node.get("colorScheme").get("foreground").textValue(), "#222222");
assertEquals(node.get("colorScheme").get("activated").textValue(), "#333333");
assertEquals(node.get("colorScheme").get("inactivated").textValue(), "#444444");
assertEquals(node.get("colorScheme").get("type").textValue(), "ColorScheme");
// shared ID also generates the correct URL
url = resolver.url("ws", "/v1/sharedassessments/guid/config");
ref.setAppId(SHARED_APP_ID);
info = AssessmentInfo.create(ref);
node = BridgeObjectMapper.get().valueToTree(info);
assertEquals(node.get("configUrl").textValue(), url);
}
use of org.sagebionetworks.bridge.models.appconfig.ConfigResolver in project BridgeServer2 by Sage-Bionetworks.
the class SurveyReferenceTest method test.
@Test
public void test() {
ConfigResolver resolver = mockConfigResolver(UAT, "ws");
SurveyReference ref = new SurveyReference(resolver, IDENTIFIER, GUID, CREATED_ON);
assertEquals(ref.getIdentifier(), IDENTIFIER);
assertEquals(ref.getGuid(), GUID);
assertEquals(ref.getCreatedOn(), CREATED_ON);
assertEquals(ref.getHref(), "https://ws-uat.bridge.org/v3/surveys/abc/revisions/2017-02-09T20:15:59.558Z");
GuidCreatedOnVersionHolder keys1 = new GuidCreatedOnVersionHolderImpl(GUID, CREATED_ON.getMillis());
assertTrue(ref.equalsSurvey(keys1));
GuidCreatedOnVersionHolder keys2 = new GuidCreatedOnVersionHolderImpl("def", CREATED_ON.getMillis());
assertFalse(ref.equalsSurvey(keys2));
// Doesn't match published links, only specific ones.
ref = new SurveyReference(IDENTIFIER, GUID, null);
assertFalse(ref.equalsSurvey(keys1));
assertFalse(ref.equalsSurvey(keys2));
// Null test (should return false)
assertFalse(ref.equalsSurvey(null));
// Same guid, different createdOn
GuidCreatedOnVersionHolder keys3 = new GuidCreatedOnVersionHolderImpl(GUID, DateTime.now().getMillis());
assertFalse(ref.equalsSurvey(keys3));
// Different guid, different createdOn
GuidCreatedOnVersionHolder keys4 = new GuidCreatedOnVersionHolderImpl("def", DateTime.now().getMillis());
assertFalse(ref.equalsSurvey(keys4));
}
use of org.sagebionetworks.bridge.models.appconfig.ConfigResolver in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentReferenceTest method configHrefChangesWithSharedAppId.
@Test
public void configHrefChangesWithSharedAppId() {
ConfigResolver resolver = mockConfigResolver(LOCAL, "ws");
AssessmentReference ref = new AssessmentReference(resolver, SHARED_APP_ID, "oneGuid", null, null);
assertEquals(ref.getConfigHref(), "http://ws-local.bridge.org/v1/sharedassessments/oneGuid/config");
}
use of org.sagebionetworks.bridge.models.appconfig.ConfigResolver in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentReferenceTest method canSerialise.
@Test
public void canSerialise() throws Exception {
ConfigResolver resolver = mockConfigResolver(LOCAL, "ws");
AssessmentReference ref = new AssessmentReference(resolver, "appId", "oneGuid", "id", "originSharedId");
JsonNode node = BridgeObjectMapper.get().valueToTree(ref);
assertEquals(node.get("appId").textValue(), "appId");
assertEquals(node.get("guid").textValue(), "oneGuid");
assertEquals(node.get("id").textValue(), "id");
assertEquals(node.get("originSharedId").textValue(), "originSharedId");
assertEquals(node.get("configHref").textValue(), "http://ws-local.bridge.org/v1/assessments/oneGuid/config");
assertEquals(node.get("type").textValue(), "AssessmentReference");
AssessmentReference deser = BridgeObjectMapper.get().readValue(node.toString(), AssessmentReference.class);
assertEquals(deser, ref);
assertEquals(deser.getAppId(), "appId");
assertEquals(deser.getGuid(), "oneGuid");
assertNull(deser.getId());
assertNull(deser.getOriginSharedId());
}
Aggregations