Skip to content

Commit

Permalink
Fixing unit tests in orcid-web
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Jan 23, 2023
1 parent 61538c4 commit ffcb83c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# General
org.orcid.frontend.freemarker.cache=freemarker.cache.NullCacheStorage
org.orcid.frontend.static.resource.cache.enabled=false
org.orcid.frontend.web.domainsAllowingRobotsAsWhiteSpaceSeparatedList=orcid.org localhost localhost:8443/orcid-web
org.orcid.frontend.web.domainsAllowingRobotsAsWhiteSpaceSeparatedList=orcid.org localhost localhost:8443/orcid-web testserver.orcid.org

# Shibboleth
org.orcid.shibboleth.enabled=true
Expand Down
18 changes: 18 additions & 0 deletions orcid-web/src/test/java/orcid/pojo/ajaxForm/DummyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package orcid.pojo.ajaxForm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.orcid.test.DBUnitTest;
import org.orcid.test.OrcidJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;

@RunWith(OrcidJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "classpath:test-frontend-web-servlet.xml" })
public class DummyTest extends DBUnitTest {

@Test
public void testThis() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,24 @@ public void testInvalidDescription() {
@Test
public void testInvalidWebsite() {
Client client = controller.getEmptyClient();
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));

// test website validation when switched off
ReflectionTestUtils.setField(controller, "validateWebsites", false);

// check empty website causes an issue
client = controller.getEmptyClient();
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("invalid"));
client = controller.createClient(client);
assertNotNull(client);
assertEquals(0, client.getErrors().size());
assertEquals(1, client.getErrors().size());

// check empty website still causes an issue
client = controller.getEmptyClient();
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());

ReflectionTestUtils.setField(controller, "validateWebsites", true);
assertEquals(controller.getMessage("common.invalid_url"), client.getErrors().get(0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,42 +249,7 @@ public void testClientValidation() throws Exception {
result = developerToolsController.createClient(client);
assertNotNull(result.getErrors());
assertEquals(result.getErrors().size(), 1);
assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.at_least_one"));

// test website validation when switched off
ReflectionTestUtils.setField(developerToolsController, "validateWebsites", false);

// empty website should behave the same
client = new Client();
client.setDisplayName(Text.valueOf("Client Name"));
client.setShortDescription(Text.valueOf("This is a description"));
redirectUris = new ArrayList<RedirectUri>();
rUri = new RedirectUri();
rUri.setType(Text.valueOf(RedirectUriType.SSO_AUTHENTICATION.value()));
rUri.setValue(Text.valueOf("https://orcid.org"));
redirectUris.add(rUri);
client.setRedirectUris(redirectUris);
result = developerToolsController.createClient(client);
assertNotNull(result.getErrors());
assertEquals(result.getErrors().size(), 1);
assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.website_not_empty"));

// invalid website should be allowed
client = new Client();
client.setDisplayName(Text.valueOf("Client Name"));
client.setShortDescription(Text.valueOf("This is a description"));
client.setWebsite(Text.valueOf("invalid"));
redirectUris = new ArrayList<RedirectUri>();
rUri = new RedirectUri();
rUri.setType(Text.valueOf(RedirectUriType.SSO_AUTHENTICATION.value()));
rUri.setValue(Text.valueOf("https://orcid.org"));
redirectUris.add(rUri);
client.setRedirectUris(redirectUris);
result = developerToolsController.createClient(client);
assertNotNull(result.getErrors());
assertEquals(result.getErrors().size(), 0);

ReflectionTestUtils.setField(developerToolsController, "validateWebsites", true);
assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.at_least_one"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ public void testUpdateWork() throws Exception {
ActivityExternalIdentifier wei1 = new ActivityExternalIdentifier();
wei1.setExternalIdentifierId(Text.valueOf("1"));
wei1.setExternalIdentifierType(Text.valueOf("doi"));
wei1.setRelationship(Text.valueOf("self"));
work.getWorkExternalIdentifiers().add(wei1);

ActivityExternalIdentifier wei2 = new ActivityExternalIdentifier();
wei2.setExternalIdentifierId(Text.valueOf("2"));
wei2.setExternalIdentifierType(Text.valueOf("arxiv"));
wei2.setRelationship(Text.valueOf("self"));
work.getWorkExternalIdentifiers().add(wei2);

work.getPublicationDate().setDay("2");
Expand Down

0 comments on commit ffcb83c

Please sign in to comment.