Search in sources :

Example 16 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class GroupAdministratorControllerTest method emptyClientTest.

@Test
@Transactional("transactionManager")
@Rollback(true)
public void emptyClientTest() {
    Client client = controller.getClient();
    client = controller.createClient(client);
    assertNotNull(client);
    List<String> errors = client.getErrors();
    assertEquals(4, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.display_name.empty")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.website.empty")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.short_description.empty")));
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
}
Also used : Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class GroupAdministratorControllerTest method testInvalidWebsite.

@Test
public void testInvalidWebsite() {
    Client client = controller.getClient();
    client.setRedirectUris(new ArrayList<RedirectUri>());
    client.setDisplayName(Text.valueOf("This is a valid name"));
    client.setShortDescription(Text.valueOf("This is a valid description"));
    client.setWebsite(Text.valueOf("http:://orcid.org"));
    client = controller.createClient(client);
    assertNotNull(client);
    assertEquals(1, client.getErrors().size());
    assertEquals(controller.getMessage("common.invalid_url"), client.getErrors().get(0));
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 18 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class ClientsControllerTest method editInvalidClientTest.

@Test
public void editInvalidClientTest() {
    // Test invalid fields
    Client client = controller.getEmptyClient();
    String _151chars = RandomStringUtils.randomAlphanumeric(151);
    client.setDisplayName(Text.valueOf(_151chars));
    client.setShortDescription(Text.valueOf("description"));
    client.setWebsite(Text.valueOf("http://site.com"));
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri one = new RedirectUri();
    one.setType(Text.valueOf("default"));
    one.setValue(Text.valueOf(""));
    redirectUris.add(one);
    client.setRedirectUris(redirectUris);
    client = controller.editClient(client);
    List<String> errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.display_name.150")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.empty_redirect_uri")));
    // Test invalid redirect uris
    client = controller.getEmptyClient();
    client.setDisplayName(Text.valueOf("Name"));
    client.setShortDescription(Text.valueOf("Description"));
    client.setWebsite(Text.valueOf("http://mysite.com"));
    redirectUris = new ArrayList<RedirectUri>();
    one = new RedirectUri();
    one.setType(Text.valueOf("default"));
    one.setValue(new Text());
    redirectUris.add(one);
    client.setRedirectUris(redirectUris);
    client = controller.editClient(client);
    errors = client.getErrors();
    assertEquals(1, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.empty_redirect_uri")));
    RedirectUri two = new RedirectUri();
    two.setType(Text.valueOf("grant-read-wizard"));
    two.setValue(new Text());
    redirectUris = new ArrayList<RedirectUri>();
    redirectUris.add(two);
    client.setRedirectUris(redirectUris);
    client = controller.editClient(client);
    errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.empty_redirect_uri")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.empty_scopes")));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 19 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class ClientsControllerTest method editClientTest.

@Test
public void editClientTest() {
    List<Client> clients = controller.getClients();
    int clientsSoFar = clients.size();
    assertNotNull(clients);
    assertEquals(2, clients.size());
    Client client = clients.get(0);
    assertEquals("APP-5555555555555555", client.getClientId().getValue());
    String random = RandomStringUtils.randomAlphanumeric(20);
    client.getDisplayName().setValue("Source Client 1 Updated");
    client.getShortDescription().setValue("Updated client description");
    client.getWebsite().setValue("http://orcid.org/" + random);
    RedirectUri newRedirectUri = new RedirectUri();
    newRedirectUri.setValue(Text.valueOf("http://orcid.org/" + random));
    newRedirectUri.setType(Text.valueOf(RedirectUriType.DEFAULT.value()));
    client.getRedirectUris().add(newRedirectUri);
    client = controller.editClient(client);
    assertTrue(client.getErrors().isEmpty());
    clients = controller.getClients();
    assertTrue(clients.size() == clientsSoFar);
    boolean found = false;
    for (Client c : clients) {
        if (client.getClientId().getValue().equals(c.getClientId().getValue())) {
            assertEquals("Source Client 1 Updated", client.getDisplayName().getValue());
            assertEquals("Updated client description", client.getShortDescription().getValue());
            assertEquals("http://orcid.org/" + random, client.getWebsite().getValue());
            boolean rUriFound = false;
            for (RedirectUri rUri : client.getRedirectUris()) {
                if (rUri.getValue().getValue().equals("http://orcid.org/" + random)) {
                    assertEquals(RedirectUriType.DEFAULT.value(), rUri.getType().getValue());
                    rUriFound = true;
                }
            }
            assertTrue(rUriFound);
            found = true;
            break;
        }
    }
    assertTrue(found);
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 20 with Client

use of org.orcid.pojo.ajaxForm.Client in project ORCID-Source by ORCID.

the class ClientsControllerTest method getClientsTest.

@Test
public void getClientsTest() {
    List<Client> clients = controller.getClients();
    assertNotNull(clients);
    assertEquals(2, clients.size());
    Client client1 = clients.get(0);
    assertEquals("APP-5555555555555555", client1.getClientId().getValue());
    Client client2 = clients.get(1);
    assertEquals("APP-5555555555555556", client2.getClientId().getValue());
}
Also used : Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Aggregations

Client (org.orcid.pojo.ajaxForm.Client)31 Test (org.junit.Test)23 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)21 ArrayList (java.util.ArrayList)14 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)14 Text (org.orcid.pojo.ajaxForm.Text)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)3 DBUnitTest (org.orcid.test.DBUnitTest)3 Rollback (org.springframework.test.annotation.Rollback)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1 Produces (javax.ws.rs.Produces)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)1 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1