Search in sources :

Example 1 with Company

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

the class TestPeople method testUpdatePersonUpdateAsAdmin.

@Test
public void testUpdatePersonUpdateAsAdmin() throws Exception {
    final String personId = account3.createUser().getId();
    publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin"));
    String firstName = "updatedFirstName";
    String lastName = "updatedLastName";
    String description = "updatedDescription";
    String email = "updated@example.com";
    String skypeId = "updated.skype.id";
    String googleId = "googleId";
    String instantMessageId = "updated.user@example.com";
    String jobTitle = "updatedJobTitle";
    String location = "updatedLocation";
    Company company = new Company("updatedOrganization", "updatedAddress1", "updatedAddress2", "updatedAddress3", "updatedPostcode", "updatedTelephone", "updatedFax", "updatedEmail");
    String mobile = "mobile";
    String telephone = "telephone";
    String userStatus = "userStatus";
    Boolean enabled = true;
    Boolean emailNotificationsEnabled = false;
    Map<String, String> params = new HashMap<>();
    params.put("fields", "id,firstName,lastName,description,avatarId,email,skypeId,googleId,instantMessageId,jobTitle,location,mobile,telephone,userStatus,emailNotificationsEnabled,enabled,company");
    HttpResponse response = people.update("people", personId, null, null, "{\n" + "  \"firstName\": \"" + firstName + "\",\n" + "  \"lastName\": \"" + lastName + "\",\n" + "  \"description\": \"" + description + "\",\n" + "  \"email\": \"" + email + "\",\n" + "  \"skypeId\": \"" + skypeId + "\",\n" + "  \"googleId\": \"" + googleId + "\",\n" + "  \"instantMessageId\": \"" + instantMessageId + "\",\n" + "  \"jobTitle\": \"" + jobTitle + "\",\n" + "  \"location\": \"" + location + "\",\n" + "  \"company\": {\n" + "    \"organization\": \"" + company.getOrganization() + "\",\n" + "    \"address1\": \"" + company.getAddress1() + "\",\n" + "    \"address2\": \"" + company.getAddress2() + "\",\n" + "    \"address3\": \"" + company.getAddress3() + "\",\n" + "    \"postcode\": \"" + company.getPostcode() + "\",\n" + "    \"telephone\": \"" + company.getTelephone() + "\",\n" + "    \"fax\": \"" + company.getFax() + "\",\n" + "    \"email\": \"" + company.getEmail() + "\"\n" + "  },\n" + "  \"mobile\": \"" + mobile + "\",\n" + "  \"telephone\": \"" + telephone + "\",\n" + "  \"userStatus\": \"" + userStatus + "\",\n" + "  \"emailNotificationsEnabled\": \"" + emailNotificationsEnabled + "\",\n" + "  \"enabled\": \"" + enabled + "\"\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    Person updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertNotNull(updatedPerson.getId());
    assertEquals(firstName, updatedPerson.getFirstName());
    assertEquals(lastName, updatedPerson.getLastName());
    assertEquals(description, updatedPerson.getDescription());
    assertEquals(email, updatedPerson.getEmail());
    assertEquals(skypeId, updatedPerson.getSkypeId());
    assertEquals(googleId, updatedPerson.getGoogleId());
    assertEquals(instantMessageId, updatedPerson.getInstantMessageId());
    assertEquals(jobTitle, updatedPerson.getJobTitle());
    assertEquals(location, updatedPerson.getLocation());
    assertNotNull(updatedPerson.getCompany());
    company.expected(updatedPerson.getCompany());
    assertEquals(mobile, updatedPerson.getMobile());
    assertEquals(telephone, updatedPerson.getTelephone());
    assertEquals(userStatus, updatedPerson.getUserStatus());
    assertEquals(emailNotificationsEnabled, updatedPerson.isEmailNotificationsEnabled());
    assertEquals(enabled, updatedPerson.isEnabled());
    // test ability to unset optional fields (could be one or more - here all) including individual company fields
    response = people.update("people", personId, null, null, "{\n" + "  \"lastName\":null,\n" + "  \"description\":null,\n" + "  \"skypeId\":null,\n" + "  \"googleId\":null,\n" + "  \"instantMessageId\":null,\n" + "  \"jobTitle\":null,\n" + "  \"location\":null,\n" + "  \"company\": {\n" + "    \"address1\":null,\n" + "    \"address2\":null,\n" + "    \"address3\":null,\n" + "    \"postcode\":null,\n" + "    \"telephone\":null,\n" + "    \"fax\":null,\n" + "    \"email\":null\n" + "  },\n" + "  \"mobile\":null,\n" + "  \"telephone\":null,\n" + "  \"userStatus\":null\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertNotNull(updatedPerson.getId());
    assertNull(updatedPerson.getLastName());
    assertNull(updatedPerson.getDescription());
    assertNull(updatedPerson.getSkypeId());
    assertNull(updatedPerson.getGoogleId());
    assertNull(updatedPerson.getInstantMessageId());
    assertNull(updatedPerson.getJobTitle());
    assertNull(updatedPerson.getLocation());
    assertNotNull(updatedPerson.getCompany());
    assertNotNull(updatedPerson.getCompany().getOrganization());
    assertNull(updatedPerson.getCompany().getAddress1());
    assertNull(updatedPerson.getCompany().getAddress2());
    assertNull(updatedPerson.getCompany().getAddress3());
    assertNull(updatedPerson.getCompany().getPostcode());
    assertNull(updatedPerson.getCompany().getFax());
    assertNull(updatedPerson.getCompany().getEmail());
    assertNull(updatedPerson.getCompany().getTelephone());
    assertNull(updatedPerson.getMobile());
    assertNull(updatedPerson.getTelephone());
    assertNull(updatedPerson.getUserStatus());
    // test ability to unset company fields as a whole
    response = people.update("people", personId, null, null, "{\n" + "  \"company\": {} \n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    // note: empty company object is returned for backwards compatibility (with pre-existing getPerson API <= 5.1)
    assertNotNull(updatedPerson.getCompany());
    assertNull(updatedPerson.getCompany().getOrganization());
    // set at least one company field
    String updatedOrgName = "another org";
    response = people.update("people", personId, null, null, "{\n" + "  \"company\": {\n" + "    \"organization\":\"" + updatedOrgName + "\"\n" + "  }\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertNotNull(updatedPerson.getCompany());
    assertEquals(updatedOrgName, updatedPerson.getCompany().getOrganization());
    // test ability to unset company fields as a whole
    response = people.update("people", personId, null, null, "{\n" + "  \"company\": null\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    // note: empty company object is returned for backwards compatibility (with pre-existing getPerson API <= 5.1)
    assertNotNull(updatedPerson.getCompany());
    assertNull(updatedPerson.getCompany().getOrganization());
}
Also used : Company(org.alfresco.rest.api.tests.client.data.Company) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 2 with Company

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

the class TestPeople method testCreatePerson.

@Test
public void testCreatePerson() throws Exception {
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
    Person person = new Person();
    person.setUserName("myUserName00@" + account1.getId());
    person.setFirstName("Firstname");
    person.setLastName("Lastname");
    person.setDescription("my description");
    person.setEmail("email@example.com");
    person.setSkypeId("my.skype.id");
    person.setGoogleId("google");
    person.setInstantMessageId("jabber@im.example.com");
    person.setJobTitle("International Man of Mystery");
    person.setLocation("location");
    person.setCompany(new Company("Org", "addr1", "addr2", "addr3", "AB1 1BA", "111 12312123", "222 345345345", "company.email@example.com"));
    person.setMobile("5657 567567 34543");
    person.setTelephone("1234 5678 9012");
    person.setUserStatus("userStatus");
    person.setEnabled(true);
    person.setEmailNotificationsEnabled(true);
    person.setPassword("password");
    Person p = people.create(person);
    assertEquals("myUserName00@" + account1.getId(), p.getId());
    assertEquals("Firstname", p.getFirstName());
    assertEquals("Lastname", p.getLastName());
    assertEquals("my description", p.getDescription());
    assertEquals("email@example.com", p.getEmail());
    assertEquals("my.skype.id", p.getSkypeId());
    assertEquals("google", p.getGoogleId());
    assertEquals("jabber@im.example.com", p.getInstantMessageId());
    assertEquals("International Man of Mystery", p.getJobTitle());
    assertEquals("location", p.getLocation());
    // Check embedded "company" document
    org.alfresco.rest.api.model.Company co = p.getCompany();
    assertEquals("Org", co.getOrganization());
    assertEquals("addr1", co.getAddress1());
    assertEquals("addr2", co.getAddress2());
    assertEquals("addr3", co.getAddress3());
    assertEquals("AB1 1BA", co.getPostcode());
    assertEquals("111 12312123", co.getTelephone());
    assertEquals("222 345345345", co.getFax());
    assertEquals("company.email@example.com", co.getEmail());
    assertEquals("5657 567567 34543", p.getMobile());
    assertEquals("1234 5678 9012", p.getTelephone());
    assertEquals("userStatus", p.getUserStatus());
    assertEquals(true, p.isEnabled());
    assertEquals(true, p.isEmailNotificationsEnabled());
    // -ve tests
    // create person with username too long
    person.setUserName("myUserName11111111111111111111111111111111111111111111111111111111111111111111111111111111@" + account1.getId());
    people.create(person, 400);
    // create person with invalid characters ("/", "\", "\n", "\r")
    {
        char[] invalidCharacters = { '/', '\\', '\n', '\r' };
        for (char invalidCharacter : invalidCharacters) {
            person.setUserName("myUser" + invalidCharacter + "Name@" + account1.getId());
            people.create(person, 400);
        }
    }
    // check for reserved authority prefixes
    person.setUserName("GROUP_EVERYONE");
    people.create(person, 400);
    person.setUserName("GROUP_mygroup");
    people.create(person, 400);
    person.setUserName("ROLE_ANYTHING");
    people.create(person, 400);
    // lower case
    person.setUserName("role_whatever");
    people.create(person, 400);
}
Also used : Company(org.alfresco.rest.api.tests.client.data.Company) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Aggregations

RequestContext (org.alfresco.rest.api.tests.client.RequestContext)2 Company (org.alfresco.rest.api.tests.client.data.Company)2 Person (org.alfresco.rest.api.tests.client.data.Person)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)1 JSONObject (org.json.simple.JSONObject)1