private ServiceDescriptor getDescriptor() throws Exception {
   String path = SERVICE_URI;
   ContainerResponse response =
       launcher.service(HttpMethod.OPTIONS, path, BASE_URI, null, null, null, null);
   Assert.assertEquals(response.getStatus(), 200);
   return (ServiceDescriptor) response.getEntity();
 }
Example #2
0
  public void testUpdatePropertiesFile2() throws Exception {
    Map<String, String[]> props = new HashMap<>(3);
    props.put("a", new String[] {"to be or not to be"});
    props.put("b", new String[] {"hello world"});
    props.put("c", new String[] {"test"});
    writeProperties(filePath, props);

    String update =
        "[{\"name\":\"b\", \"value\":[\"TEST\"]}," //
            + "{\"name\":\"c\", \"value\":[\"TEST\"]}," //
            + "{\"name\":\"d\", \"value\":[\"TEST\", \"TEST\"]}]";

    String requestPath = SERVICE_URI + "item/" + fileId;
    Map<String, List<String>> h = new HashMap<>(1);
    h.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
    ContainerResponse response =
        launcher.service(HttpMethod.POST, requestPath, BASE_URI, h, update.getBytes(), null);
    assertEquals("Error: " + response.getEntity(), 200, response.getStatus());

    Map<String, String[]> expectedProperties = new HashMap<>(4);
    expectedProperties.put("a", new String[] {"to be or not to be"});
    expectedProperties.put("b", new String[] {"TEST"});
    expectedProperties.put("c", new String[] {"TEST"});
    expectedProperties.put("d", new String[] {"TEST", "TEST"});
    validateProperties(filePath, expectedProperties);

    Item item = getItem(fileId);
    assertEquals("to be or not to be", getPropertyValue(item, "a")); // not updated
    assertEquals("TEST", getPropertyValue(item, "b"));
    assertEquals("TEST", getPropertyValue(item, "c"));
    assertEquals(Arrays.asList("TEST", "TEST"), getPropertyValues(item, "d"));
  }
Example #3
0
 public void testUploadFileAlreadyExists() throws Exception {
   String fileName = "existedFile.txt";
   VirtualFile folder = mountPoint.getVirtualFileById(uploadTestFolderId);
   folder.createFile(fileName, new ByteArrayInputStream(DEFAULT_CONTENT.getBytes()));
   ContainerResponse response = doUploadFile(fileName, DEFAULT_CONTENT, "", "", false);
   assertEquals(200, response.getStatus());
   String entity = (String) response.getEntity();
   assertTrue(entity.contains("Item with the same name exists"));
   log.info(entity);
 }
Example #4
0
  public void testUpdatePropertiesFile() throws Exception {
    String update = "[{\"name\":\"MyProperty\", \"value\":[\"MyValue\"]}]";

    String requestPath = SERVICE_URI + "item/" + fileId;
    Map<String, List<String>> h = new HashMap<>(1);
    h.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
    ContainerResponse response =
        launcher.service(HttpMethod.POST, requestPath, BASE_URI, h, update.getBytes(), null);
    assertEquals("Error: " + response.getEntity(), 200, response.getStatus());

    Map<String, String[]> expectedProperties = new HashMap<>(1);
    expectedProperties.put("MyProperty", new String[] {"MyValue"});
    validateProperties(filePath, expectedProperties);

    Item item = getItem(fileId);
    assertEquals("MyValue", getPropertyValue(item, "MyProperty"));
  }
Example #5
0
  public void testUpdateFileHavePermissions() throws Exception {
    String properties = "[{\"name\":\"MyProperty\", \"value\":[\"MyValue\"]}]";

    String requestPath = SERVICE_URI + "item/" + protectedFileId;
    Map<String, List<String>> h = new HashMap<>(1);
    h.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
    ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
    // File is protected and default principal 'andrew' has not write permission.
    // Replace default principal by principal who has write permission.
    EnvironmentContext.getCurrent()
        .setUser(
            new UserImpl("andrew", "andrew", null, Arrays.asList("workspace/developer"), false));
    ContainerResponse response =
        launcher.service(
            HttpMethod.POST, requestPath, BASE_URI, h, properties.getBytes(), writer, null);
    assertEquals("Error: " + response.getEntity(), 200, response.getStatus());

    Map<String, String[]> expectedProperties = new HashMap<>(1);
    expectedProperties.put("MyProperty", new String[] {"MyValue"});
    validateProperties(protectedFilePath, expectedProperties);

    Item item = getItem(protectedFileId);
    assertEquals("MyValue", getPropertyValue(item, "MyProperty"));
  }