Search in sources :

Example 1 with Link

use of com.opentext.ia.sdk.support.http.rest.Link in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingInfoArchive method shouldQuerySuccessfully.

@Test
public void shouldQuerySuccessfully() throws IOException {
    when(aics.getItems()).thenReturn(Stream.of(aic));
    Link dipLink = new Link();
    dipLink.setHref(randomString());
    aic.getLinks().put(LINK_DIP, dipLink);
    aic.setName("MyAic");
    UriBuilder uriBuilder = mock(UriBuilder.class);
    String uri = randomString();
    when(uriBuilder.build()).thenReturn(uri);
    when(uriBuilder.addParameter(anyString(), anyString())).thenReturn(uriBuilder);
    when(restClient.uri(anyString())).thenReturn(uriBuilder);
    QueryResultFactory queryResultFactory = mock(QueryResultFactory.class);
    DefaultQueryResult queryResult = mock(DefaultQueryResult.class);
    when(queryResultFactory.create(any(Response.class), any(Runnable.class))).thenReturn(queryResult);
    when(restClient.get(eq(uri), any(QueryResultFactory.class))).thenReturn(queryResult);
    SearchQuery query = new SearchQuery();
    query.getItems().add(new Comparison("variable", Operator.EQUAL, "value"));
    String aicName = "MyAic";
    String schema = NAMESPACE;
    configureServer();
    QueryResult result = archiveClient.query(query, aicName, schema, 10);
    assertEquals(queryResult, result);
}
Also used : SearchQuery(com.opentext.ia.sdk.dto.query.SearchQuery) QueryResult(com.opentext.ia.sdk.client.api.QueryResult) Comparison(com.opentext.ia.sdk.dto.query.Comparison) Link(com.opentext.ia.sdk.support.http.rest.Link) Test(org.junit.Test)

Example 2 with Link

use of com.opentext.ia.sdk.support.http.rest.Link in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingInfoArchive method getOrderItemLog.

@Test
void getOrderItemLog() throws IOException {
    OrderItem firstOrderItem = new OrderItem();
    Map<String, Link> link = new HashMap<>();
    link.put(InfoArchiveLinkRelations.LINK_LOG, new Link("uri-for-orderitem-log"));
    firstOrderItem.setLinks(link);
    when(restClient.get("uri-for-orderitem-log", String.class)).thenReturn("id: abc, \"logMessages\" : [ { sample data } ]");
    String logJson = JobsUtil.getLog(firstOrderItem, connection.getRestClient());
    assertThat(logJson, notNullValue());
    assertThat(logJson, containsString("\"logMessages\" : [ {"));
}
Also used : HashMap(java.util.HashMap) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Link(com.opentext.ia.sdk.support.http.rest.Link) Test(org.junit.jupiter.api.Test)

Example 3 with Link

use of com.opentext.ia.sdk.support.http.rest.Link in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingInfoArchive method init.

@BeforeEach
public void init() throws IOException {
    prepareConfiguration();
    connection = new PropertiesBasedArchiveConnection(configuration);
    connection.setRestClient(restClient);
    Services resource = new Services();
    Link link = mock(Link.class);
    Tenant tenant = new Tenant();
    application = new Application();
    applications = mock(Applications.class);
    federations = mock(XdbFederations.class);
    Spaces spaces = mock(Spaces.class);
    XdbDatabases databases = mock(XdbDatabases.class);
    FileSystemRoots fileSystemRoots = mock(FileSystemRoots.class);
    FileSystemRoot fileSystemRoot = new FileSystemRoot();
    when(fileSystemRoots.first()).thenReturn(fileSystemRoot);
    Holdings holdings = mock(Holdings.class);
    ReceiverNodes receiverNodes = mock(ReceiverNodes.class);
    SpaceRootXdbLibraries spaceRootLibraries = mock(SpaceRootXdbLibraries.class);
    SpaceRootFolders rootFolders = mock(SpaceRootFolders.class);
    FileSystemFolders systemFolders = mock(FileSystemFolders.class);
    Stores stores = mock(Stores.class);
    IngestNodes ingestionNodes = mock(IngestNodes.class);
    RetentionPolicies retentionPolicies = mock(RetentionPolicies.class);
    Pdis pdis = mock(Pdis.class);
    PdiSchemas pdiSchemas = mock(PdiSchemas.class);
    Ingests ingests = mock(Ingests.class);
    XdbLibraries libraries = mock(XdbLibraries.class);
    Contents contents = new Contents();
    Aics aics = mock(Aics.class);
    LinkContainer aips = new LinkContainer();
    Queries queries = mock(Queries.class);
    QueryQuotas quotas = mock(QueryQuotas.class);
    ResultConfigurationHelpers helpers = mock(ResultConfigurationHelpers.class);
    ExportConfigurations exportConfigurations = mock(ExportConfigurations.class);
    ExportPipelines exportPipelines = mock(ExportPipelines.class);
    ExportTransformations exportTransformations = mock(ExportTransformations.class);
    Searches searches = mock(Searches.class);
    SearchCompositions compositions = mock(SearchCompositions.class);
    XForms xForms = mock(XForms.class);
    XForm xForm = mock(XForm.class);
    CryptoObjects cryptoObjects = mock(CryptoObjects.class);
    PdiCryptoes pdiCryptos = mock(PdiCryptoes.class);
    HoldingCryptoes holdingCryptos = mock(HoldingCryptoes.class);
    StorageEndPoints storageEndPoints = mock(StorageEndPoints.class);
    CustomStorages customStorages = mock(CustomStorages.class);
    ContentAddressedStorages contentAddressedStorages = mock(ContentAddressedStorages.class);
    Aic aic = new Aic();
    links.put(InfoArchiveLinkRelations.LINK_TENANT, link);
    links.put(InfoArchiveLinkRelations.LINK_APPLICATIONS, link);
    links.put(InfoArchiveLinkRelations.LINK_AIPS, link);
    links.put(InfoArchiveLinkRelations.LINK_INGEST, link);
    resource.setLinks(links);
    tenant.setLinks(links);
    application.setLinks(links);
    contents.getLinks().put(LINK_DOWNLOAD, new Link());
    when(restClient.follow(any(LinkContainer.class), eq(LINK_CONTENTS), eq(Contents.class))).thenReturn(contents);
    when(restClient.get(BILLBOARD_URI, Services.class)).thenReturn(resource);
    when(restClient.follow(resource, LINK_TENANT, Tenant.class)).thenReturn(tenant);
    ProductInfo productInfo = new ProductInfo();
    BuildProperties buildProperties = new BuildProperties();
    buildProperties.setServerVersion("16.3");
    productInfo.setBuildProperties(buildProperties);
    when(restClient.follow(resource, LINK_PRODUCT_INFO, ProductInfo.class)).thenReturn(productInfo);
    when(link.getHref()).thenReturn(BILLBOARD_URI);
    when(restClient.follow(application, InfoArchiveLinkRelations.LINK_AIPS, LinkContainer.class)).thenReturn(aips);
    aips.setLinks(links);
    mockCollection(Applications.class, applications);
    mockCollection(XdbFederations.class, federations);
    mockCollection(Spaces.class, spaces);
    mockCollection(XdbDatabases.class, databases);
    mockCollection(FileSystemRoots.class, fileSystemRoots);
    mockCollection(Holdings.class, holdings);
    mockCollection(ReceiverNodes.class, receiverNodes);
    mockCollection(SpaceRootXdbLibraries.class, spaceRootLibraries);
    mockCollection(SpaceRootFolders.class, rootFolders);
    mockCollection(FileSystemFolders.class, systemFolders);
    mockCollection(Stores.class, stores);
    mockCollection(IngestNodes.class, ingestionNodes);
    mockCollection(RetentionPolicies.class, retentionPolicies);
    mockCollection(Pdis.class, pdis);
    mockCollection(PdiSchemas.class, pdiSchemas);
    mockCollection(Ingests.class, ingests);
    mockCollection(XdbLibraries.class, libraries);
    mockCollection(Aics.class, aics);
    mockCollection(QueryQuotas.class, quotas);
    mockCollection(Queries.class, queries);
    mockCollection(ResultConfigurationHelpers.class, helpers);
    mockCollection(ExportConfigurations.class, exportConfigurations);
    mockCollection(ExportPipelines.class, exportPipelines);
    mockCollection(ExportTransformations.class, exportTransformations);
    mockCollection(Searches.class, searches);
    mockCollection(SearchCompositions.class, compositions);
    mockCollection(XForms.class, xForms);
    mockCollection(CryptoObjects.class, cryptoObjects);
    mockCollection(PdiCryptoes.class, pdiCryptos);
    mockCollection(HoldingCryptoes.class, holdingCryptos);
    mockCollection(StorageEndPoints.class, storageEndPoints);
    mockCollection(CustomStorages.class, customStorages);
    mockCollection(ContentAddressedStorages.class, contentAddressedStorages);
    when(restClient.createCollectionItem(any(LinkContainer.class), any(XForm.class), eq(LINK_SELF))).thenReturn(xForm);
    mockByName(federations, new XdbFederation());
    mockByName(databases, new XdbDatabase());
    mockByName(applications, application);
    mockByName(spaces, new Space());
    mockByName(spaceRootLibraries, new SpaceRootXdbLibrary());
    mockByName(rootFolders, new SpaceRootFolder());
    mockByName(fileSystemRoots, new FileSystemRoot());
    mockByName(systemFolders, new FileSystemFolder());
    mockByName(stores, new Store());
    mockByName(receiverNodes, new ReceiverNode());
    mockByName(ingestionNodes, new IngestNode());
    mockByName(retentionPolicies, new RetentionPolicy());
    mockByName(pdis, new Pdi());
    mockByName(pdiSchemas, new PdiSchema());
    mockByName(ingests, new Ingest());
    mockByName(libraries, new XdbLibrary());
    mockByName(holdings, new Holding());
    mockByName(aics, aic);
    mockByName(quotas, new QueryQuota());
    mockByName(queries, new Query());
    mockByName(helpers, new ResultConfigurationHelper());
    mockByName(exportConfigurations, new ExportConfiguration());
    mockByName(exportPipelines, new ExportPipeline());
    mockByName(exportTransformations, new ExportTransformation());
    mockByName(searches, new Search());
    mockByName(compositions, new SearchComposition());
    mockByName(xForms, new XForm());
    mockByName(cryptoObjects, new CryptoObject());
    mockByName(pdiCryptos, new PdiCrypto());
    mockByName(holdingCryptos, new HoldingCrypto());
    mockByName(storageEndPoints, new StorageEndPoint());
    mockByName(customStorages, new CustomStorage());
    mockByName(contentAddressedStorages, new ContentAddressedStorage());
    when(restClient.put(any(), eq(SearchComposition.class), any(AllSearchComponents.class))).thenReturn(new SearchComposition());
    when(aics.getItems()).thenReturn(Stream.of(aic));
}
Also used : SearchQuery(com.opentext.ia.sdk.dto.query.SearchQuery) AllSearchComponents(com.opentext.ia.sdk.dto.result.AllSearchComponents) ExportPipelines(com.opentext.ia.sdk.dto.export.ExportPipelines) PropertiesBasedArchiveConnection(com.opentext.ia.sdk.server.configuration.PropertiesBasedArchiveConnection) LinkContainer(com.opentext.ia.sdk.support.http.rest.LinkContainer) BuildProperties(com.opentext.ia.sdk.dto.ProductInfo.BuildProperties) Link(com.opentext.ia.sdk.support.http.rest.Link) ExportPipeline(com.opentext.ia.sdk.dto.export.ExportPipeline) ExportConfiguration(com.opentext.ia.sdk.dto.export.ExportConfiguration) ExportConfigurations(com.opentext.ia.sdk.dto.export.ExportConfigurations) ExportTransformations(com.opentext.ia.sdk.dto.export.ExportTransformations) ExportTransformation(com.opentext.ia.sdk.dto.export.ExportTransformation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Link

use of com.opentext.ia.sdk.support.http.rest.Link in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingInfoArchive method shouldFetchOrderContentSuccessfully.

@Test
@SuppressWarnings("rawtypes")
public void shouldFetchOrderContentSuccessfully() throws IOException {
    UriBuilder uriBuilder = mock(UriBuilder.class);
    String uri = randomString();
    when(uriBuilder.build()).thenReturn(uri);
    when(uriBuilder.addParameter(anyString(), anyString())).thenReturn(uriBuilder);
    when(restClient.uri(anyString())).thenReturn(uriBuilder);
    ResponseFactory contentResultFactory = mock(ContentResultFactory.class);
    DefaultContentResult contentResult = mock(DefaultContentResult.class);
    when(contentResultFactory.create(any(Response.class), any(Runnable.class))).thenReturn(contentResult);
    when(restClient.get(eq(uri), any(ContentResultFactory.class))).thenReturn(contentResult);
    OrderItem orderItem = new OrderItem();
    orderItem.setType("EXPORT");
    Link downloadLink = new Link();
    downloadLink.setHref(randomString());
    orderItem.getLinks().put(LINK_DOWNLOAD, downloadLink);
    configureServer();
    ContentResult result = archiveClient.fetchOrderContent(orderItem);
    assertEquals(contentResult, result);
}
Also used : Response(com.opentext.ia.sdk.support.http.Response) ContentResult(com.opentext.ia.sdk.client.api.ContentResult) DefaultContentResult(com.opentext.ia.sdk.client.impl.DefaultContentResult) ResponseFactory(com.opentext.ia.sdk.support.http.ResponseFactory) DefaultContentResult(com.opentext.ia.sdk.client.impl.DefaultContentResult) ContentResultFactory(com.opentext.ia.sdk.client.impl.ContentResultFactory) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UriBuilder(com.opentext.ia.sdk.support.http.UriBuilder) Link(com.opentext.ia.sdk.support.http.rest.Link) Test(org.junit.jupiter.api.Test)

Example 5 with Link

use of com.opentext.ia.sdk.support.http.rest.Link in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenUsingInfoArchive method shouldSearchSuccessfully.

@Test
void shouldSearchSuccessfully() throws IOException {
    SearchResults searchResults = mock(SearchResults.class);
    when(searchResults.getUri("next")).thenReturn(null);
    when(restClient.post(anyString(), eq(SearchResults.class), anyString(), eq(MediaTypes.XML))).thenReturn(searchResults);
    SearchQuery searchQuery = new SearchQuery();
    List<Item> items = new ArrayList<>();
    items.add(new Comparison("from", Operator.EQUAL, ""));
    items.add(new Comparison("recipient", Operator.EQUAL, ""));
    List<String> dates = new ArrayList<>();
    dates.add("2014-04-27");
    dates.add("2016-10-11");
    items.add(new Comparison("sentDate", Operator.BETWEEN, dates));
    items.add(new Comparison("fromCountry", Operator.STARTS_WITH, ""));
    items.add(new Comparison("toCountry", Operator.NOT_EQUAL, ""));
    searchQuery.setItems(items);
    SearchComposition searchComparison = new SearchComposition();
    Map<String, Link> searchComparisonLinks = new HashMap<>();
    Link compositionLink = new Link();
    compositionLink.setHref(randomString());
    searchComparisonLinks.put("self", compositionLink);
    searchComparison.setLinks(searchComparisonLinks);
    configureServer();
    SearchResults result = archiveClient.search(searchQuery, searchComparison);
    assertEquals(searchResults, result);
}
Also used : SearchQuery(com.opentext.ia.sdk.dto.query.SearchQuery) Item(com.opentext.ia.sdk.dto.query.Item) Comparison(com.opentext.ia.sdk.dto.query.Comparison) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Link(com.opentext.ia.sdk.support.http.rest.Link) Test(org.junit.jupiter.api.Test)

Aggregations

Link (com.opentext.ia.sdk.support.http.rest.Link)9 Test (org.junit.jupiter.api.Test)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)6 HashMap (java.util.HashMap)4 SearchQuery (com.opentext.ia.sdk.dto.query.SearchQuery)3 Comparison (com.opentext.ia.sdk.dto.query.Comparison)2 ContentResult (com.opentext.ia.sdk.client.api.ContentResult)1 QueryResult (com.opentext.ia.sdk.client.api.QueryResult)1 ContentResultFactory (com.opentext.ia.sdk.client.impl.ContentResultFactory)1 DefaultContentResult (com.opentext.ia.sdk.client.impl.DefaultContentResult)1 BuildProperties (com.opentext.ia.sdk.dto.ProductInfo.BuildProperties)1 Services (com.opentext.ia.sdk.dto.Services)1 ExportConfiguration (com.opentext.ia.sdk.dto.export.ExportConfiguration)1 ExportConfigurations (com.opentext.ia.sdk.dto.export.ExportConfigurations)1 ExportPipeline (com.opentext.ia.sdk.dto.export.ExportPipeline)1 ExportPipelines (com.opentext.ia.sdk.dto.export.ExportPipelines)1 ExportTransformation (com.opentext.ia.sdk.dto.export.ExportTransformation)1 ExportTransformations (com.opentext.ia.sdk.dto.export.ExportTransformations)1 Item (com.opentext.ia.sdk.dto.query.Item)1