@Test public void testException() throws Exception { LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, entityResource); Response response = mock(Response.class); when(entityResource.submit(any(HttpServletRequest.class))) .thenThrow(new WebApplicationException(response)); when(response.getEntity()) .thenReturn( new JSONObject() { { put("stackTrace", "stackTrace"); } }); when(response.getStatus()).thenReturn(Response.Status.BAD_REQUEST.getStatusCode()); try { atlasClient.createEntity(new Referenceable(random())); fail("Expected AtlasServiceException"); } catch (AtlasServiceException e) { assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST); } when(entityResource.updateByUniqueAttribute( anyString(), anyString(), anyString(), any(HttpServletRequest.class))) .thenThrow(new WebApplicationException(response)); when(response.getStatus()).thenReturn(Response.Status.NOT_FOUND.getStatusCode()); try { atlasClient.updateEntity(random(), random(), random(), new Referenceable(random())); fail("Expected AtlasServiceException"); } catch (AtlasServiceException e) { assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND); } }
@Test public void testCreateEntity() throws Exception { Response response = mock(Response.class); when(entityResource.submit(any(HttpServletRequest.class))).thenReturn(response); final String guid = random(); when(response.getEntity()) .thenReturn( new JSONObject() { { put( ENTITIES, new JSONObject( new AtlasClient.EntityResult(Arrays.asList(guid), null, null) .toString()) .get(ENTITIES)); } }); LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, entityResource); List<String> results = atlasClient.createEntity(new Referenceable(random())); assertEquals(results.size(), 1); assertEquals(results.get(0), guid); }