Ejemplo n.º 1
0
  @Test
  public void getTopologyWhileAuthenticated() {
    final Topology mockedTopology = RandomGenerator.randomObject(Topology.class);

    doReturn(mockedTopology)
        .when(topologyServiceMock)
        .getTopology(mockedTopology.getId(), TEST_SUBJECT_ID);

    mockAuthenticatedSubject();

    Topology responseTopology =
        resource()
            .path("/api/topologies/" + mockedTopology.getId())
            .accept(MediaType.APPLICATION_JSON)
            .get(Topology.class);

    assertEquals(
        "Response topology should match the mocked topology", mockedTopology, responseTopology);

    verify(topologyServiceMock).getTopology(anyString(), anyString());
  }
Ejemplo n.º 2
0
  @Test
  public void updateTopologyConfigWhileAuthenticated() {
    final Topology mockedTopology = RandomGenerator.randomObject(Topology.class);
    final TopologyConfig requestTopologyConfig = RandomGenerator.randomObject(TopologyConfig.class);

    doReturn(mockedTopology)
        .when(topologyServiceMock)
        .getTopology(mockedTopology.getId(), TEST_SUBJECT_ID);
    doNothing()
        .when(topologyServiceMock)
        .updateTopology(mockedTopology.getId(), mockedTopology, TEST_SUBJECT_ID);

    mockAuthenticatedSubject();

    ClientResponse clientResponse =
        resource()
            .path("/api/topologies/" + mockedTopology.getId() + "/config")
            .type(MediaType.APPLICATION_JSON)
            .put(ClientResponse.class, requestTopologyConfig);

    assertEquals("Response HTTP status code should be 200 (OK)", clientResponse.getStatus(), 200);

    verify(topologyServiceMock).getTopology(mockedTopology.getId(), TEST_SUBJECT_ID);
    verify(topologyServiceMock)
        .updateTopology(mockedTopology.getId(), mockedTopology, TEST_SUBJECT_ID);
  }
Ejemplo n.º 3
0
  @Test
  public void listTopologiesWhileAuthenticated() {
    Topology topology1 = RandomGenerator.randomObject(Topology.class);
    topology1.setName("Topology First");

    Topology topology2 = RandomGenerator.randomObject(Topology.class);
    topology2.setName("Topology Second");

    Topology topology3 = RandomGenerator.randomObject(Topology.class);
    topology3.setName("Topology Third");

    List<Topology> mockedTopologies = new ArrayList<Topology>();
    mockedTopologies.add(topology1);
    mockedTopologies.add(topology2);
    mockedTopologies.add(topology3);

    doReturn(mockedTopologies).when(topologyServiceMock).listTopologies(TEST_SUBJECT_ID);

    mockAuthenticatedSubject();

    List<Topology> responseUsers =
        resource()
            .path("/api/topologies")
            .accept(MediaType.APPLICATION_JSON)
            .get(new GenericType<List<Topology>>() {});

    assertEquals(
        "Response topologies should be equal to the mocked topologies",
        mockedTopologies,
        responseUsers);

    verify(topologyServiceMock).listTopologies(TEST_SUBJECT_ID);
  }
Ejemplo n.º 4
0
  @Test
  public void submitTopologyWhileAuthenticated() {
    final String requestClusterId = "LOCAL";
    final String requestLogLevel = "INFO";
    final String requestClassLoaderPolicy = "FRAMEWORK_FIRST";
    final Topology mockedTopology = RandomGenerator.randomObject(Topology.class);

    doReturn(mockedTopology)
        .when(topologyServiceMock)
        .submitTopology(
            mockedTopology.getId(),
            TEST_SUBJECT_ID,
            requestClusterId,
            requestLogLevel,
            requestClassLoaderPolicy);

    mockAuthenticatedSubject();

    Topology responseTopology =
        resource()
            .path("/api/topologies/" + mockedTopology.getId() + "/submit")
            .queryParam("clusterId", requestClusterId)
            .accept(MediaType.APPLICATION_JSON)
            .get(Topology.class);

    assertEquals(
        "Response topology should match the mocked topology", mockedTopology, responseTopology);

    verify(topologyServiceMock)
        .submitTopology(
            mockedTopology.getId(),
            TEST_SUBJECT_ID,
            requestClusterId,
            requestLogLevel,
            requestClassLoaderPolicy);
  }