@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 testUpdateEntity() throws Exception { final String guid = random(); Response response = mock(Response.class); when(entityResource.updateByUniqueAttribute( anyString(), anyString(), anyString(), any(HttpServletRequest.class))) .thenReturn(response); when(response.getEntity()) .thenReturn( new JSONObject() { { put( ENTITIES, new JSONObject( new AtlasClient.EntityResult(null, Arrays.asList(guid), null) .toString()) .get(ENTITIES)); } }); LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, entityResource); AtlasClient.EntityResult entityResult = atlasClient.updateEntity(random(), random(), random(), new Referenceable(random())); assertEquals(entityResult.getUpdateEntities(), Arrays.asList(guid)); }