Search in sources :

Example 1 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class TestCswQueryResponseTransformer method testMarshalAcknowledgement.

@Test
public void testMarshalAcknowledgement() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
    GetRecordsType query = new GetRecordsType();
    query.setResultType(ResultType.VALIDATE);
    query.setMaxRecords(BigInteger.valueOf(6));
    query.setStartPosition(BigInteger.valueOf(4));
    SourceResponse sourceResponse = createSourceResponse(query, 22);
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.RESULT_TYPE_PARAMETER, ResultType.VALIDATE);
    args.put(CswConstants.GET_RECORDS, query);
    BinaryContent content = transformer.transform(sourceResponse, args);
    String xml = new String(content.getByteArray());
    JAXBElement<?> jaxb = (JAXBElement<?>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    assertThat(jaxb.getValue(), is(instanceOf(AcknowledgementType.class)));
    AcknowledgementType response = (AcknowledgementType) jaxb.getValue();
    assertThat(response.getEchoedRequest().getAny(), is(instanceOf(JAXBElement.class)));
    JAXBElement<?> jaxB = (JAXBElement<?>) response.getEchoedRequest().getAny();
    assertThat(jaxB.getValue(), is(instanceOf(GetRecordsType.class)));
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) BinaryContent(ddf.catalog.data.BinaryContent) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 2 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class TestCswSource method testRefreshWithRegisterForEvents.

@Test
public void testRefreshWithRegisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    CswSubscribe client = mock(CswSubscribe.class);
    Response response = mock(Response.class);
    AcknowledgementType ack = mock(AcknowledgementType.class);
    when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
    when(response.getStatus()).thenReturn(200);
    when(response.readEntity(any(Class.class))).thenReturn(ack);
    when(ack.getRequestId()).thenReturn(subscriptionId);
    when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
    // Set Configuration Map
    Map<String, Object> configuration = getConfigurationMap(cswSource);
    configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
    configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
    // Call Refresh
    cswSource.refresh(configuration);
    // Get Configuration
    CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
    // Assert Refresh Changes
    Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
    Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
    verify(ack).getRequestId();
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 3 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class CswSubscriptionEndpointTest method testUpdateRecordsSubscription.

@Test
public void testUpdateRecordsSubscription() throws Exception {
    GetRecordsRequest getRecordsRequest = createDefaultGetRecordsRequest();
    getRecordsRequest.setResponseHandler(RESPONSE_HANDLER_URL);
    Response response = cswSubscriptionEndpoint.createRecordsSubscription(getRecordsRequest);
    AcknowledgementType createAck = (AcknowledgementType) response.getEntity();
    getRecordsRequest = createDefaultGetRecordsRequest();
    getRecordsRequest.setResponseHandler(RESPONSE_HANDLER_URL);
    getRecordsRequest.setResultType(ResultType.HITS.value());
    response = cswSubscriptionEndpoint.updateRecordsSubscription(createAck.getRequestId(), getRecordsRequest.get202RecordsType());
    AcknowledgementType updateAck = (AcknowledgementType) response.getEntity();
    assertThat(((GetRecordsType) ((JAXBElement) updateAck.getEchoedRequest().getAny()).getValue()).getResultType(), is(ResultType.HITS));
    verify(serviceRegistration).unregister();
    verify(config).delete();
    verify(mockContext, times(2)).registerService(eq(Subscription.class.getName()), any(Subscription.class), any(Dictionary.class));
}
Also used : Response(javax.ws.rs.core.Response) Dictionary(java.util.Dictionary) JAXBElement(javax.xml.bind.JAXBElement) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) GetRecordsRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest) Test(org.junit.Test)

Example 4 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class CswSubscriptionEndpointTest method testGetRecordsSubscription.

@Test
public void testGetRecordsSubscription() throws Exception {
    cswSubscriptionEndpoint.addOrUpdateSubscription(defaultRequest.get202RecordsType(), true);
    Response response = cswSubscriptionEndpoint.getRecordsSubscription(subscriptionId);
    AcknowledgementType getAck = (AcknowledgementType) response.getEntity();
    assertThat(defaultRequest.get202RecordsType(), is(((JAXBElement<GetRecordsType>) getAck.getEchoedRequest().getAny()).getValue()));
    verify(mockContext).getService(eq(subscriptionReference));
}
Also used : Response(javax.ws.rs.core.Response) JAXBElement(javax.xml.bind.JAXBElement) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 5 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class CswSourceTest method testRefreshWithRegisterForEvents.

@Test
public void testRefreshWithRegisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    CswSubscribe client = mock(CswSubscribe.class);
    Response response = mock(Response.class);
    AcknowledgementType ack = mock(AcknowledgementType.class);
    when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
    when(response.getStatus()).thenReturn(200);
    when(response.readEntity(any(Class.class))).thenReturn(ack);
    when(ack.getRequestId()).thenReturn(subscriptionId);
    when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
    when(cswSource.getSubscriberClientFactory().getClientForSystemSubject(cswSource.getSubject())).thenReturn(client);
    // Set Configuration Map
    Map<String, Object> configuration = getConfigurationMap(cswSource);
    configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
    configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
    // Call Refresh
    cswSource.refresh(configuration);
    // Get Configuration
    CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
    // Assert Refresh Changes
    Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
    Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
    verify(ack).getRequestId();
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Aggregations

AcknowledgementType (net.opengis.cat.csw.v_2_0_2.AcknowledgementType)15 Test (org.junit.Test)12 Response (javax.ws.rs.core.Response)11 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)10 SourceResponse (ddf.catalog.operation.SourceResponse)9 ResourceResponse (ddf.catalog.operation.ResourceResponse)7 CswSubscribe (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe)7 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)6 JAXBElement (javax.xml.bind.JAXBElement)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Subscription (ddf.catalog.event.Subscription)3 Dictionary (java.util.Dictionary)3 GetRecordsRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest)3 CswSubscription (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription)3 BinaryContent (ddf.catalog.data.BinaryContent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 EchoedRequestType (net.opengis.cat.csw.v_2_0_2.EchoedRequestType)2