use of org.sagebionetworks.bridge.validators.AppValidator in project BridgeServer2 by Sage-Bionetworks.
the class BridgeExceptionHandlerTest method bridgeValidationExceptionCorrectlyReported.
@Test
public void bridgeValidationExceptionCorrectlyReported() throws Throwable {
App app = new DynamoApp();
try {
Validate.entityThrowingException(new AppValidator(), app);
fail("Should have thrown exception");
} catch (InvalidEntityException e) {
MethodInvocation invocation = mock(MethodInvocation.class);
when(invocation.proceed()).thenThrow(e);
ResponseEntity<String> response = handler.handleException(mockRequest, e);
JsonNode node = new ObjectMapper().readTree(response.getBody());
assertEquals(node.size(), 5);
assertEquals(node.get("errors").get("identifier").get(0).textValue(), "identifier is required");
assertEquals(node.get("type").textValue(), "InvalidEntityException");
assertNotNull(node.get("entity"));
assertNotNull(node.get("errors"));
assertEquals(response.getStatusCodeValue(), 400);
assertEquals(node.get("statusCode").intValue(), 400);
// Verify log.
verify(logger).info(contains(e.getMessage()));
}
}
use of org.sagebionetworks.bridge.validators.AppValidator in project BridgeServer2 by Sage-Bionetworks.
the class AppServiceTest method before.
@BeforeMethod
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
// Mock config.
when(mockBridgeConfig.get(AppService.CONFIG_KEY_SUPPORT_EMAIL_PLAIN)).thenReturn(SUPPORT_EMAIL);
when(mockBridgeConfig.get(AppService.CONFIG_KEY_TEAM_BRIDGE_ADMIN)).thenReturn(String.valueOf(BRIDGE_ADMIN_TEAM_ID));
when(mockBridgeConfig.get(AppService.CONFIG_KEY_TEAM_BRIDGE_STAFF)).thenReturn(String.valueOf(BRIDGE_STAFF_TEAM_ID));
when(mockBridgeConfig.getPropertyAsList(AppService.CONFIG_APP_WHITELIST)).thenReturn(ImmutableList.of(API_APP_ID));
when(mockBridgeConfig.get(AppService.CONFIG_KEY_SYNAPSE_TRACKING_VIEW)).thenReturn(SYNAPSE_TRACKING_VIEW_ID);
// this has to be set again after being mocked
service.setBridgeConfig(mockBridgeConfig);
// Mock templates
service.setAppEmailVerificationTemplateSubject(mockTemplateAsSpringResource("Verify your app email"));
service.setAppEmailVerificationTemplate(mockTemplateAsSpringResource("Click here ${appEmailVerificationUrl} ${appEmailVerificationExpirationPeriod}" + " ${studyEmailVerificationUrl} ${studyEmailVerificationExpirationPeriod}"));
service.setValidator(new AppValidator());
AppAndUsersValidator appAndUsersValidator = new AppAndUsersValidator();
appAndUsersValidator.setSynapseClient(mockSynapseClient);
service.setAppAndUsersValidator(appAndUsersValidator);
when(service.getNameScopingToken()).thenReturn(TEST_NAME_SCOPING_TOKEN);
app = getTestApp();
app.setIdentifier(TEST_APP_ID);
when(mockAppDao.getApp(TEST_APP_ID)).thenReturn(app);
GuidVersionHolder keys = new GuidVersionHolder("guid", 1L);
when(mockTemplateService.createTemplate(any(), any())).thenReturn(keys);
when(mockAppDao.createApp(any())).thenAnswer(invocation -> {
// Return the same app, except set version to 1.
App app = invocation.getArgument(0);
app.setVersion(1L);
return app;
});
when(mockAppDao.updateApp(any())).thenAnswer(invocation -> {
// Return the same app, except we increment the version.
App app = invocation.getArgument(0);
Long oldVersion = app.getVersion();
app.setVersion(oldVersion != null ? oldVersion + 1 : 1);
return app;
});
// Spy AppService.createTimeLimitedToken() to create a known token instead of a random one. This makes our
// tests easier.
doReturn(VERIFICATION_TOKEN).when(service).createTimeLimitedToken();
// setup project and team
team = new Team();
project = new Project();
project.setId(TEST_PROJECT_ID);
team.setId(TEST_TEAM_ID);
teamMemberInvitation = new MembershipInvitation();
teamMemberInvitation.setInviteeId(TEST_USER_ID.toString());
teamMemberInvitation.setTeamId(TEST_TEAM_ID);
}
Aggregations