Search in sources :

Example 1 with GuidHolder

use of org.sagebionetworks.bridge.models.GuidHolder in project BridgeServer2 by Sage-Bionetworks.

the class NotificationRegistrationControllerTest method createRegistration.

@Test
public void createRegistration() throws Exception {
    // Mock service.
    doReturn(createRegList().get(0)).when(mockNotificationService).createRegistration(any(), any(), any());
    // Mock Play context.
    String json = TestUtils.createJson("{'deviceId':'" + DEVICE_ID + "','osName':'" + OS_NAME + "'}");
    mockRequestBody(mockRequest, json);
    // Execute and validate.
    GuidHolder result = controller.createRegistration();
    assertEquals(result.getGuid(), GUID);
    // Verify service.
    verify(mockNotificationService).createRegistration(eq(TEST_APP_ID), any(), registrationCaptor.capture());
    NotificationRegistration registration = registrationCaptor.getValue();
    assertEquals(registration.getDeviceId(), DEVICE_ID);
    assertEquals(registration.getOsName(), OS_NAME);
    assertEquals(registration.getHealthCode(), HEALTH_CODE);
}
Also used : NotificationRegistration(org.sagebionetworks.bridge.models.notifications.NotificationRegistration) GuidHolder(org.sagebionetworks.bridge.models.GuidHolder) Test(org.testng.annotations.Test)

Example 2 with GuidHolder

use of org.sagebionetworks.bridge.models.GuidHolder in project BridgeServer2 by Sage-Bionetworks.

the class NotificationRegistrationControllerTest method updateRegistration.

@Test
public void updateRegistration() throws Exception {
    doReturn(createRegList().get(0)).when(mockNotificationService).updateRegistration(any(), any());
    String json = TestUtils.createJson("{'guid':'guidWeIgnore','deviceId':'NEW_DEVICE_ID','osName':'" + OS_NAME + "'}");
    mockRequestBody(mockRequest, json);
    GuidHolder result = controller.updateRegistration(GUID);
    assertEquals(result.getGuid(), GUID);
    verify(mockNotificationService).updateRegistration(eq(TEST_APP_ID), registrationCaptor.capture());
    NotificationRegistration registration = registrationCaptor.getValue();
    assertEquals(registration.getDeviceId(), "NEW_DEVICE_ID");
    assertEquals(registration.getOsName(), OS_NAME);
    assertEquals(registration.getHealthCode(), HEALTH_CODE);
    assertEquals(registration.getGuid(), GUID);
}
Also used : NotificationRegistration(org.sagebionetworks.bridge.models.notifications.NotificationRegistration) GuidHolder(org.sagebionetworks.bridge.models.GuidHolder) Test(org.testng.annotations.Test)

Example 3 with GuidHolder

use of org.sagebionetworks.bridge.models.GuidHolder in project BridgeServer2 by Sage-Bionetworks.

the class NotificationTopicControllerTest method createTopic.

@Test
public void createTopic() throws Exception {
    doReturn(mockUserSession).when(controller).getAuthenticatedSession(DEVELOPER);
    NotificationTopic topic = getNotificationTopic();
    mockRequestBody(mockRequest, topic);
    doReturn(topic).when(mockTopicService).createTopic(any());
    GuidHolder result = controller.createTopic();
    assertEquals(result.getGuid(), GUID);
    verify(mockTopicService).createTopic(topicCaptor.capture());
    NotificationTopic captured = topicCaptor.getValue();
    assertEquals(captured.getName(), topic.getName());
}
Also used : NotificationTopic(org.sagebionetworks.bridge.models.notifications.NotificationTopic) GuidHolder(org.sagebionetworks.bridge.models.GuidHolder) Test(org.testng.annotations.Test)

Example 4 with GuidHolder

use of org.sagebionetworks.bridge.models.GuidHolder in project BridgeServer2 by Sage-Bionetworks.

the class NotificationTopicController method createTopic.

@PostMapping("/v3/topics")
@ResponseStatus(HttpStatus.CREATED)
public GuidHolder createTopic() {
    UserSession session = getAuthenticatedSession(DEVELOPER);
    NotificationTopic topic = parseJson(NotificationTopic.class);
    topic.setAppId(session.getAppId());
    NotificationTopic saved = topicService.createTopic(topic);
    return new GuidHolder(saved.getGuid());
}
Also used : NotificationTopic(org.sagebionetworks.bridge.models.notifications.NotificationTopic) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) GuidHolder(org.sagebionetworks.bridge.models.GuidHolder) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 5 with GuidHolder

use of org.sagebionetworks.bridge.models.GuidHolder in project BridgeServer2 by Sage-Bionetworks.

the class NotificationTopicControllerTest method updateTopic.

@Test
public void updateTopic() throws Exception {
    doReturn(mockUserSession).when(controller).getAuthenticatedSession(DEVELOPER);
    NotificationTopic topic = getNotificationTopic();
    doReturn(topic).when(mockTopicService).updateTopic(any());
    mockRequestBody(mockRequest, topic);
    GuidHolder result = controller.updateTopic(GUID);
    assertEquals(result.getGuid(), GUID);
    verify(mockTopicService).updateTopic(topicCaptor.capture());
    NotificationTopic returned = topicCaptor.getValue();
    assertEquals(returned.getName(), topic.getName());
    assertEquals(returned.getGuid(), GUID);
}
Also used : NotificationTopic(org.sagebionetworks.bridge.models.notifications.NotificationTopic) GuidHolder(org.sagebionetworks.bridge.models.GuidHolder) Test(org.testng.annotations.Test)

Aggregations

GuidHolder (org.sagebionetworks.bridge.models.GuidHolder)8 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)4 NotificationRegistration (org.sagebionetworks.bridge.models.notifications.NotificationRegistration)4 NotificationTopic (org.sagebionetworks.bridge.models.notifications.NotificationTopic)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 Test (org.testng.annotations.Test)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2