Search in sources :

Example 1 with ConfigResolver

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);
}
Also used : ConfigResolver(org.sagebionetworks.bridge.models.appconfig.ConfigResolver) BridgeConfig(org.sagebionetworks.bridge.config.BridgeConfig)

Example 2 with ConfigResolver

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);
}
Also used : ConfigResolver(org.sagebionetworks.bridge.models.appconfig.ConfigResolver) Label(org.sagebionetworks.bridge.models.Label) ColorScheme(org.sagebionetworks.bridge.models.assessments.ColorScheme) JsonNode(com.fasterxml.jackson.databind.JsonNode) AssessmentReference(org.sagebionetworks.bridge.models.schedules2.AssessmentReference) Test(org.testng.annotations.Test)

Example 3 with ConfigResolver

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));
}
Also used : GuidCreatedOnVersionHolderImpl(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl) ConfigResolver(org.sagebionetworks.bridge.models.appconfig.ConfigResolver) TestUtils.mockConfigResolver(org.sagebionetworks.bridge.TestUtils.mockConfigResolver) GuidCreatedOnVersionHolder(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolder) Test(org.testng.annotations.Test)

Example 4 with ConfigResolver

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");
}
Also used : ConfigResolver(org.sagebionetworks.bridge.models.appconfig.ConfigResolver) TestUtils.mockConfigResolver(org.sagebionetworks.bridge.TestUtils.mockConfigResolver) Test(org.testng.annotations.Test)

Example 5 with ConfigResolver

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());
}
Also used : ConfigResolver(org.sagebionetworks.bridge.models.appconfig.ConfigResolver) TestUtils.mockConfigResolver(org.sagebionetworks.bridge.TestUtils.mockConfigResolver) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Aggregations

ConfigResolver (org.sagebionetworks.bridge.models.appconfig.ConfigResolver)10 Test (org.testng.annotations.Test)9 TestUtils.mockConfigResolver (org.sagebionetworks.bridge.TestUtils.mockConfigResolver)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 BridgeConfig (org.sagebionetworks.bridge.config.BridgeConfig)1 GuidCreatedOnVersionHolder (org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolder)1 GuidCreatedOnVersionHolderImpl (org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl)1 Label (org.sagebionetworks.bridge.models.Label)1 ColorScheme (org.sagebionetworks.bridge.models.assessments.ColorScheme)1 AssessmentReference (org.sagebionetworks.bridge.models.schedules2.AssessmentReference)1