Search in sources :

Example 16 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class AuthenticationsTest method testAuthChallenge.

private void testAuthChallenge(String expectedScheme) throws Exception {
    // Unauthorized call
    setRequestContext(null);
    HttpResponse response = getAll(SiteEntityResource.class, getPaging(0, 100), null, 401);
    String authenticateHeader = response.getHeaders().get("WWW-Authenticate");
    assertNotNull("Expected an authentication challenge", authenticateHeader);
    // Other parts may contain, e.g. realm="..."
    String authScheme = authenticateHeader.split(" ")[0];
    assertEquals(expectedScheme, authScheme);
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse)

Example 17 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class BaseCustomModelApiTest method createCustomModel.

protected CustomModel createCustomModel(String modelName, Pair<String, String> namespacePair, ModelStatus status, String desc, String author) throws Exception {
    CustomModel customModel = new CustomModel();
    customModel.setName(modelName);
    customModel.setNamespaceUri(namespacePair.getFirst());
    customModel.setNamespacePrefix(namespacePair.getSecond());
    customModel.setDescription(desc);
    customModel.setStatus(status);
    customModel.setAuthor(author);
    // Create the model as a Model Administrator
    HttpResponse response = post("cmm", RestApiUtil.toJsonAsString(customModel), 201);
    CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
    if (author == null) {
        // ignore 'author' in the comparison
        compareCustomModels(customModel, returnedModel, "author");
    } else {
        compareCustomModels(customModel, returnedModel);
    }
    return customModel;
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModel(org.alfresco.rest.api.model.CustomModel)

Example 18 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class DiscoveryApiTest method testGetDiscovery.

/**
 * Tests get discovery.
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/discovery}
 */
@Test
public void testGetDiscovery() throws Exception {
    setRequestContext(null, user1, "wrongPassword");
    get("discovery", null, 401);
    setRequestContext(null, user1, null);
    HttpResponse response = get("discovery", null, 200);
    DiscoveryDetails discoveryDetails = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), DiscoveryDetails.class);
    assertNotNull(discoveryDetails);
    RepositoryInfo repositoryInfo = discoveryDetails.getRepository();
    assertNotNull(repositoryInfo);
    assertEquals("repoId", repositoryInfo.getId());
    assertEquals("Enterprise", repositoryInfo.getEdition());
    // Check version info
    VersionInfo versionInfo = repositoryInfo.getVersion();
    assertNotNull(versionInfo);
    assertEquals("5", versionInfo.getMajor());
    assertEquals("2", versionInfo.getMinor());
    assertEquals("1", versionInfo.getPatch());
    assertEquals("3", versionInfo.getHotfix());
    assertEquals("r123456-b0", versionInfo.getLabel());
    assertEquals(10051, versionInfo.getSchema());
    assertEquals("5.2.1.3 (r123456-b0) schema 10051", versionInfo.getDisplay());
    // Check license info
    LicenseInfo licenseInfo = repositoryInfo.getLicense();
    assertNotNull(licenseInfo);
    assertEquals(LicenseMode.ENTERPRISE.name(), licenseInfo.getMode());
    assertEquals(licenseIssuedAt.toString(), licenseInfo.getIssuedAt().toString());
    assertEquals(licenseExpiresAt.toString(), licenseInfo.getExpiresAt().toString());
    assertEquals(Integer.valueOf(5), licenseInfo.getRemainingDays());
    assertEquals("Alfresco Dev Test", licenseInfo.getHolder());
    LicenseEntitlement entitlements = licenseInfo.getEntitlements();
    assertNotNull(entitlements);
    assertNotNull(entitlements.getMaxUsers());
    assertEquals(20L, entitlements.getMaxUsers().longValue());
    assertNotNull(entitlements.getMaxDocs());
    assertEquals(1000L, entitlements.getMaxDocs().longValue());
    assertTrue(entitlements.getIsClusterEnabled());
    assertFalse(entitlements.getIsCryptodocEnabled());
    // Check status
    StatusInfo statusInfo = repositoryInfo.getStatus();
    assertNotNull(statusInfo);
    assertFalse(statusInfo.getIsReadOnly());
    assertTrue(statusInfo.getIsAuditEnabled());
    assertTrue(statusInfo.getIsQuickShareEnabled());
    assertTrue(statusInfo.getIsThumbnailGenerationEnabled());
    // Check modules
    List<ModulePackage> modulePackageList = repositoryInfo.getModules();
    assertNotNull(modulePackageList);
}
Also used : VersionInfo(org.alfresco.rest.api.model.RepositoryInfo.VersionInfo) LicenseInfo(org.alfresco.rest.api.model.RepositoryInfo.LicenseInfo) ModulePackage(org.alfresco.rest.api.model.ModulePackage) RepositoryInfo(org.alfresco.rest.api.model.RepositoryInfo) StatusInfo(org.alfresco.rest.api.model.RepositoryInfo.StatusInfo) LicenseEntitlement(org.alfresco.rest.api.model.RepositoryInfo.LicenseEntitlement) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) DiscoveryDetails(org.alfresco.rest.api.model.DiscoveryDetails) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 19 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class DiscoveryApiTest method testGetDiscovery_licenseEntitlement.

/**
 * Tests get discovery.
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/discovery}
 */
@Test
public void testGetDiscovery_licenseEntitlement() throws Exception {
    // Override maxUsers
    when(licenseDescriptorMock.getMaxUsers()).thenReturn(null);
    setRequestContext(null, user1, null);
    HttpResponse response = get("discovery", null, 200);
    DiscoveryDetails discoveryDetails = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), DiscoveryDetails.class);
    assertNotNull(discoveryDetails);
    RepositoryInfo repositoryInfo = discoveryDetails.getRepository();
    assertNotNull(repositoryInfo);
    assertEquals("Enterprise", repositoryInfo.getEdition());
    // Check license info
    LicenseInfo licenseInfo = repositoryInfo.getLicense();
    assertNotNull(licenseInfo);
    assertEquals(LicenseMode.ENTERPRISE.name(), licenseInfo.getMode());
    assertEquals(licenseIssuedAt.toString(), licenseInfo.getIssuedAt().toString());
    assertEquals(licenseExpiresAt.toString(), licenseInfo.getExpiresAt().toString());
    assertEquals(Integer.valueOf(5), licenseInfo.getRemainingDays());
    assertEquals("Alfresco Dev Test", licenseInfo.getHolder());
    LicenseEntitlement entitlements = licenseInfo.getEntitlements();
    assertNotNull(entitlements);
    assertNull(entitlements.getMaxUsers());
    assertEquals(1000L, entitlements.getMaxDocs().longValue());
    assertTrue(entitlements.getIsClusterEnabled());
    assertFalse(entitlements.getIsCryptodocEnabled());
    // Override entitlements
    when(licenseDescriptorMock.getMaxDocs()).thenReturn(null);
    when(licenseDescriptorMock.isClusterEnabled()).thenReturn(false);
    when(licenseDescriptorMock.isCryptodocEnabled()).thenReturn(true);
    response = get("discovery", null, 200);
    discoveryDetails = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), DiscoveryDetails.class);
    assertNotNull(discoveryDetails);
    repositoryInfo = discoveryDetails.getRepository();
    assertNotNull(repositoryInfo);
    // Check license info
    licenseInfo = repositoryInfo.getLicense();
    assertNotNull(licenseInfo);
    entitlements = licenseInfo.getEntitlements();
    assertNotNull(entitlements);
    assertNull(entitlements.getMaxUsers());
    assertNull(entitlements.getMaxDocs());
    assertFalse(entitlements.getIsClusterEnabled());
    assertTrue(entitlements.getIsCryptodocEnabled());
}
Also used : LicenseInfo(org.alfresco.rest.api.model.RepositoryInfo.LicenseInfo) RepositoryInfo(org.alfresco.rest.api.model.RepositoryInfo) LicenseEntitlement(org.alfresco.rest.api.model.RepositoryInfo.LicenseEntitlement) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) DiscoveryDetails(org.alfresco.rest.api.model.DiscoveryDetails) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 20 with HttpResponse

use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.

the class ModulePackagesApiTest method testAllModulePackages.

@Test
public void testAllModulePackages() throws Exception {
    setRequestContext(nonAdminUserName);
    HttpResponse response = getAll(MODULEPACKAGES, null, HttpStatus.SC_OK);
    assertNotNull(response);
    PublicApiClient.ExpectedPaging paging = parsePaging(response.getJsonResponse());
    assertNotNull(paging);
    if (paging.getCount() > 0) {
        List<ModulePackage> modules = parseRestApiEntries(response.getJsonResponse(), ModulePackage.class);
        assertNotNull(modules);
        assertEquals(paging.getCount().intValue(), modules.size());
    }
}
Also used : ModulePackage(org.alfresco.rest.api.model.ModulePackage) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) Test(org.junit.Test)

Aggregations

HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)162 Test (org.junit.Test)114 HashMap (java.util.HashMap)59 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)50 Document (org.alfresco.rest.api.tests.client.data.Document)49 Node (org.alfresco.rest.api.tests.client.data.Node)49 LinkedHashMap (java.util.LinkedHashMap)31 ArrayList (java.util.ArrayList)29 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)27 Folder (org.alfresco.rest.api.tests.client.data.Folder)26 File (java.io.File)25 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)25 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)22 CustomModel (org.alfresco.rest.api.model.CustomModel)16 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)15 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)15 JSONObject (org.json.simple.JSONObject)15 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Map (java.util.Map)13 CustomAspect (org.alfresco.rest.api.model.CustomAspect)13