Search in sources :

Example 21 with TransactionResultEntity

use of org.apache.nifi.web.api.entity.TransactionResultEntity in project nifi by apache.

the class TestDataTransferResource method testCommitOutputPortTransactionBadChecksum.

@Test
public void testCommitOutputPortTransactionBadChecksum() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    final HttpFlowFileServerProtocol serverProtocol = resource.getHttpFlowFileServerProtocol(null);
    doThrow(new HandshakeException(ResponseCode.BAD_CHECKSUM, "Bad checksum.")).when(serverProtocol).commitTransferTransaction(any(), any());
    final ServletContext context = null;
    final InputStream inputStream = null;
    final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
    final String transactionId = transactionManager.createTransaction();
    final Response response = resource.commitOutputPortTransaction(ResponseCode.CONFIRM_TRANSACTION.getCode(), "client-checksum", "port-id", transactionId, req, context, inputStream);
    transactionManager.cancelTransaction(transactionId);
    TransactionResultEntity resultEntity = (TransactionResultEntity) response.getEntity();
    assertEquals(400, response.getStatus());
    assertEquals(ResponseCode.BAD_CHECKSUM.getCode(), resultEntity.getResponseCode());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) InputStream(java.io.InputStream) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) HttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol) ServletContext(javax.servlet.ServletContext) HandshakeException(org.apache.nifi.remote.exception.HandshakeException) Test(org.junit.Test)

Example 22 with TransactionResultEntity

use of org.apache.nifi.web.api.entity.TransactionResultEntity in project nifi by apache.

the class TestDataTransferResource method testCommitInputPortTransaction.

@Test
public void testCommitInputPortTransaction() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    final ServletContext context = null;
    final InputStream inputStream = null;
    final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
    final String transactionId = transactionManager.createTransaction();
    final Response response = resource.commitInputPortTransaction(ResponseCode.CONFIRM_TRANSACTION.getCode(), "port-id", transactionId, req, context, inputStream);
    transactionManager.cancelTransaction(transactionId);
    TransactionResultEntity resultEntity = (TransactionResultEntity) response.getEntity();
    assertEquals(200, response.getStatus());
    assertEquals(ResponseCode.CONFIRM_TRANSACTION.getCode(), resultEntity.getResponseCode());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) InputStream(java.io.InputStream) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 23 with TransactionResultEntity

use of org.apache.nifi.web.api.entity.TransactionResultEntity in project nifi by apache.

the class TestDataTransferResource method testExtendTransaction.

@Test
public void testExtendTransaction() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    final String locationUriStr = "http://localhost:8080/nifi-api/data-transfer/input-ports/port-id/transactions/transaction-id";
    final ServletContext context = null;
    final HttpServletResponse res = null;
    final UriInfo uriInfo = mockUriInfo(locationUriStr);
    final InputStream inputStream = null;
    final HttpRemoteSiteListener transactionManager = HttpRemoteSiteListener.getInstance(NiFiProperties.createBasicNiFiProperties(null, null));
    final String transactionId = transactionManager.createTransaction();
    final Response response = resource.extendPortTransactionTTL("input-ports", "port-id", transactionId, req, res, context, uriInfo, inputStream);
    transactionManager.cancelTransaction(transactionId);
    TransactionResultEntity resultEntity = (TransactionResultEntity) response.getEntity();
    assertEquals(200, response.getStatus());
    assertEquals(ResponseCode.CONTINUE_TRANSACTION.getCode(), resultEntity.getResponseCode());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) InputStream(java.io.InputStream) HttpRemoteSiteListener(org.apache.nifi.remote.HttpRemoteSiteListener) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 24 with TransactionResultEntity

use of org.apache.nifi.web.api.entity.TransactionResultEntity in project nifi by apache.

the class TestDataTransferResource method testCreateTransaction.

@Test
public void testCreateTransaction() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final DataTransferResource resource = getDataTransferResource();
    final String locationUriStr = "http://localhost:8080/nifi-api/data-transfer/input-ports/port-id/transactions/transaction-id";
    final ServletContext context = null;
    final UriInfo uriInfo = mockUriInfo(locationUriStr);
    final InputStream inputStream = null;
    final Response response = resource.createPortTransaction("input-ports", "port-id", req, context, uriInfo, inputStream);
    TransactionResultEntity resultEntity = (TransactionResultEntity) response.getEntity();
    assertEquals(201, response.getStatus());
    assertEquals(ResponseCode.PROPERTIES_OK.getCode(), resultEntity.getResponseCode());
    assertEquals(locationUriStr, response.getMetadata().getFirst(HttpHeaders.LOCATION_HEADER_NAME).toString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) InputStream(java.io.InputStream) ServletContext(javax.servlet.ServletContext) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

TransactionResultEntity (org.apache.nifi.web.api.entity.TransactionResultEntity)24 Test (org.junit.Test)16 InputStream (java.io.InputStream)12 ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)12 Peer (org.apache.nifi.remote.Peer)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 Response (javax.ws.rs.core.Response)9 HandshakeException (org.apache.nifi.remote.exception.HandshakeException)9 ServletContext (javax.servlet.ServletContext)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 ByteArrayInputStream (org.apache.nifi.stream.io.ByteArrayInputStream)8 SiteToSiteRestApiClient (org.apache.nifi.remote.util.SiteToSiteRestApiClient)7 HttpCommunicationsSession (org.apache.nifi.remote.io.http.HttpCommunicationsSession)6 HttpFlowFileServerProtocol (org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol)6 IOException (java.io.IOException)5 UriInfo (javax.ws.rs.core.UriInfo)5 UnknownHostException (java.net.UnknownHostException)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)4 HttpRemoteSiteListener (org.apache.nifi.remote.HttpRemoteSiteListener)4