コード例 #1
0
  @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);
    }
  }
コード例 #2
0
  @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));
  }
コード例 #3
0
  @Test
  public void testIsServerReady() throws Exception {
    when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.ACTIVE);
    LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, entityResource);
    assertTrue(atlasClient.isServerReady());

    when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.BECOMING_ACTIVE);
    assertFalse(atlasClient.isServerReady());
  }
コード例 #4
0
  @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);
  }
コード例 #5
0
  @Test
  public void testDeleteEntity() throws Exception {
    final String guid = random();
    Response response = mock(Response.class);
    when(response.getEntity())
        .thenReturn(
            new JSONObject() {
              {
                put(
                    ENTITIES,
                    new JSONObject(
                            new AtlasClient.EntityResult(null, null, Arrays.asList(guid))
                                .toString())
                        .get(ENTITIES));
              }
            });

    when(entityResource.deleteEntities(
            anyListOf(String.class), anyString(), anyString(), anyString()))
        .thenReturn(response);
    LocalAtlasClient atlasClient = new LocalAtlasClient(serviceState, entityResource);
    AtlasClient.EntityResult entityResult = atlasClient.deleteEntity(random(), random(), random());
    assertEquals(entityResult.getDeletedEntities(), Arrays.asList(guid));
  }