Search in sources :

Example 11 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class StructuredEventFilterTest method filter.

@Test
void filter() throws IOException {
    MultivaluedMap<String, String> headersMap = createRequestHeader();
    ContainerRequest requestContext = createRequestContext(headersMap);
    underTest.filter(requestContext);
    RestRequestDetails requestDetais = (RestRequestDetails) requestContext.getProperty("REQUEST_DETAIS");
    headersMap.forEach((key, value) -> assertEquals(value.get(0), requestDetais.getHeaders().get(key)));
}
Also used : RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) Test(org.junit.jupiter.api.Test)

Example 12 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackNotFound.

@Test
public void testRequestParametersWhenStackNotFound() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceName("name");
    operation.setWorkspaceId(123L);
    event.setOperation(operation);
    RestCallDetails restCall = new RestCallDetails();
    event.setRestCall(restCall);
    RestRequestDetails restRequest = new RestRequestDetails();
    restCall.setRestRequest(restRequest);
    Map<String, Object> params = new HashMap<>();
    when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
    when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.empty());
    Map<String, Object> actual = underTest.requestParameters(event);
    Assertions.assertEquals(0, actual.size());
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Test(org.junit.jupiter.api.Test)

Example 13 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundButNotScaling.

@Test
public void testRequestParametersWhenStackFoundButNotScaling() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceName("name");
    operation.setWorkspaceId(123L);
    event.setOperation(operation);
    RestCallDetails restCall = new RestCallDetails();
    event.setRestCall(restCall);
    RestRequestDetails restRequest = new RestRequestDetails();
    restRequest.setMethod("POST");
    restCall.setRestRequest(restRequest);
    Stack stack = new Stack();
    Map<String, Object> params = new HashMap<>();
    when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
    when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
    Map<String, Object> actual = underTest.requestParameters(event);
    Assertions.assertEquals(0, actual.size());
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 14 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheOperationButExistInRequestAndResponse.

@Test
public void testWhenNameAndResourceCrnComeFromTheOperationButExistInRequestAndResponse() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceCrn("crn1");
    operation.setResourceName("name1");
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    request.setBody(new Json(Map.of("name", "name2", "resourceCrn", "crn2")).getValue());
    RestResponseDetails response = new RestResponseDetails();
    response.setBody(new Json(Map.of("name", "name3", "resourceCrn", "crn3")).getValue());
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "name1");
    expected.put(CLUSTER_CRN, "crn1");
    Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
    assertEquals(expected, actual);
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 15 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheResponse.

@Test
public void testWhenNameAndResourceCrnComeFromTheResponse() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    RestResponseDetails response = new RestResponseDetails();
    response.setBody(new Json(Map.of("name", "name3", "resourceCrn", "crn3")).getValue());
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "name3");
    expected.put(CLUSTER_CRN, "crn3");
    Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
    assertEquals(expected, actual);
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Aggregations

RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)40 HashMap (java.util.HashMap)29 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)25 Test (org.junit.jupiter.api.Test)23 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)20 Json (com.sequenceiq.cloudbreak.common.json.Json)15 StructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent)11 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)8 Map (java.util.Map)6 OutputStream (java.io.OutputStream)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FilterOutputStream (java.io.FilterOutputStream)2 Entry (java.util.Map.Entry)2 MediaType (javax.ws.rs.core.MediaType)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 RestResourceAuditEventConverter (com.sequenceiq.cloudbreak.structuredevent.auditeventname.rest.RestResourceAuditEventConverter)1