Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package it.de.aservo.confapi.crowd.rest;

import de.aservo.confapi.commons.constants.ConfAPI;
import de.aservo.confapi.commons.model.ApplicationLinkBean;
import de.aservo.confapi.commons.model.ApplicationLinksBean;
import it.de.aservo.confapi.commons.rest.ResourceBuilder;
import org.apache.wink.client.ClientResponse;
import org.apache.wink.client.Resource;
import org.junit.Test;

import javax.ws.rs.core.Response;
import java.util.UUID;

import static org.junit.Assert.assertEquals;

public class ApplicationLinksResourceFuncTest {

@Test
public void testGetAllApplicationLinks() {
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
ApplicationLinksBean applicationLinksBean = clientResponse.getEntity(ApplicationLinksBean.class);
assertEquals(1, applicationLinksBean.getApplicationLinks().size());
}

@Test
public void testGetIdApplicationLink() {
UUID applicationLinkUuid = createApplicationLinkGetId(ApplicationLinkBean.EXAMPLE_1);

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS + "/" + applicationLinkUuid + "?ignore-setup-errors=true").build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
assertEquals(applicationLinkUuid, clientResponse.getEntity(ApplicationLinkBean.class).getUuid());
}

@Test
public void testDeleteAllApplicationLinks() {
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS + "?force=true").build();
ClientResponse clientResponse = resource.delete();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
ClientResponse clientGetResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientGetResponse.getStatusCode());
ApplicationLinksBean applicationLinksBean = clientGetResponse.getEntity(ApplicationLinksBean.class);
assertEquals(0, applicationLinksBean.getApplicationLinks().size());
}

@Test
public void testDeleteIdApplicationLink() {
UUID applicationLinkUuid = createApplicationLinkGetId(ApplicationLinkBean.EXAMPLE_1);

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS + "/" + applicationLinkUuid + "?ignore-setup-errors=true").build();
ClientResponse clientResponse = resource.delete();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
ClientResponse clientGetResponse = resource.get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), clientGetResponse.getStatusCode());
}

@Test
public void testPutAllApplicationLinks() {// TODO
UUID applicationLinkUuidExampleOne = createApplicationLinkGetId(ApplicationLinkBean.EXAMPLE_1);
UUID applicationLinkUuidExampleTwo = createApplicationLinkGetId(ApplicationLinkBean.EXAMPLE_1);

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS + "?ignore-setup-errors=true").build();
ClientResponse clientResponse = resource.put(ApplicationLinksBean.EXAMPLE_1);
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
}

@Test
public void testPutIdApplicationLink() {// TODO
UUID applicationLinkUuid = createApplicationLinkGetId(ApplicationLinkBean.EXAMPLE_1);

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS + "/" + applicationLinkUuid + "?ignore-setup-errors=true").build();
ApplicationLinkBean exampleBean = ApplicationLinkBean.EXAMPLE_1;
exampleBean.setUsername("new-user");
ClientResponse clientResponse = resource.put(exampleBean);
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
ClientResponse clientGetResponse = resource.get();
assertEquals(clientGetResponse.getEntity(ApplicationLinkBean.class).getName(),exampleBean.getUsername());
}

@Test
public void testAddNewApplicationLink() {
UUID applicationLinkUuid = createApplicationLinkGetId(ApplicationLinkBean.EXAMPLE_1);

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS + "/" + applicationLinkUuid + "?ignore-setup-errors=true").build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
assertEquals(applicationLinkUuid, clientResponse.getEntity(ApplicationLinkBean.class).getUuid());
}

private UUID createApplicationLinkGetId(ApplicationLinkBean bean) {
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATION_LINKS + "?ignore-setup-errors=true").build();
ClientResponse clientResponse = resource.post(bean);

return clientResponse.getEntity(ApplicationLinkBean.class).getUuid();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package it.de.aservo.confapi.crowd.rest;

import de.aservo.confapi.commons.constants.ConfAPI;
import de.aservo.confapi.crowd.model.ApplicationBean;
import de.aservo.confapi.crowd.model.ApplicationsBean;
import it.de.aservo.confapi.commons.rest.ResourceBuilder;
import org.apache.wink.client.ClientResponse;
import org.apache.wink.client.Resource;
import org.junit.Test;

import javax.ws.rs.core.Response;
import java.util.Collections;

import static org.junit.Assert.assertEquals;

public class ApplicationsResourceFuncTest {

@Test
public void testGetAllApplications() {
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
ApplicationsBean response = clientResponse.getEntity(ApplicationsBean.class);
assertEquals(4, response.getApplications().size());
}

@Test
public void testGetIdApplication() {
Long applicationId = createApplicationGetId(createApplicationBeanWithName("ExampleBean"));

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS + "/" + applicationId).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
assertEquals(applicationId, clientResponse.getEntity(ApplicationBean.class).getId());
}

@Test
public void testDeleteAllApplications() {
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS + "/?force=true").build();
ClientResponse clientResponse = resource.delete();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
ClientResponse clientGetResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientGetResponse.getStatusCode());
ApplicationsBean response = clientGetResponse.getEntity(ApplicationsBean.class);
assertEquals(2, response.getApplications().size());
}

@Test
public void testDeleteIdApplication() {
Long applicationId = createApplicationGetId(createApplicationBeanWithName("ExampleBean2"));

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS + "/" + applicationId).build();
ClientResponse clientResponse = resource.delete();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
ClientResponse clientGetResponse = resource.get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), clientGetResponse.getStatusCode());
}

@Test
public void testDeleteIdApplicationWithError() {
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS + "/1").build();
ClientResponse clientResponse = resource.delete();
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), clientResponse.getStatusCode());
}

@Test
public void testPutAllApplications() {// TODO
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS).build();
createApplicationBeanWithName("Example1");
createApplicationBeanWithName("Example2");
ClientResponse clientResponse = resource.put(new ApplicationsBean((Collections.singletonList(ApplicationBean.EXAMPLE_1))));
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
}

@Test
public void testPutIdApplication() { // TODO
Long applicationId = createApplicationGetId(createApplicationBeanWithName("testPutExample"));

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS + "/" + applicationId).build();
ClientResponse clientResponse = resource.put(ApplicationBean.EXAMPLE_2);
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
}

@Test
public void testAddNewApplication() {
Long applicationId = createApplicationGetId(ApplicationBean.EXAMPLE_1);

Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS + "/" + applicationId).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
assertEquals( applicationId, clientResponse.getEntity(ApplicationBean.class).getId());
}

private Long createApplicationGetId(ApplicationBean bean) {
Resource resource = ResourceBuilder.builder(ConfAPI.APPLICATIONS).build();
ClientResponse clientResponse = resource.post(bean);

return clientResponse.getEntity(ApplicationBean.class).getId();
}

private ApplicationBean createApplicationBeanWithName (String name) {
ApplicationBean applicationBean = new ApplicationBean();
applicationBean.setName(name);
applicationBean.setDescription(name);
applicationBean.setActive(true);
applicationBean.setPassword("3x4mpl3");
applicationBean.setType(ApplicationBean.ApplicationType.GENERIC);

return applicationBean;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package it.de.aservo.confapi.crowd.rest;

import de.aservo.confapi.commons.constants.ConfAPI;
import de.aservo.confapi.commons.model.DirectoriesBean;
import it.de.aservo.confapi.commons.rest.ResourceBuilder;
import org.apache.wink.client.ClientResponse;
import org.apache.wink.client.Resource;
import org.junit.Test;

import javax.ws.rs.core.Response;

import static org.junit.Assert.assertEquals;

public class DirectoriesResourceFuncTest {

@Test
public void testGetAllDirectories() {
Resource resource = ResourceBuilder.builder(ConfAPI.DIRECTORIES).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
DirectoriesBean directoriesBean = clientResponse.getEntity(DirectoriesBean.class);
assertEquals(1, directoriesBean.getDirectories().size());
}

@Test
public void testGetIdDirectory() {
//The ID need to be hardcoded here because there is no Add method to generate and catch the ID for a test directory
Resource resource = ResourceBuilder.builder(ConfAPI.DIRECTORIES + "/131073").build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package it.de.aservo.confapi.crowd.rest;

import de.aservo.confapi.commons.model.LicensesBean;
import it.de.aservo.confapi.commons.rest.AbstractLicenseResourceFuncTest;
import org.junit.Ignore;
import org.junit.Test;

public class LicensesResourceFuncTest extends AbstractLicenseResourceFuncTest {

@Override
protected LicensesBean getExampleBean() {
return LicensesBean.EXAMPLE_2_DEVELOPER_LICENSE;
}

@Test
@Ignore("There is no set method to test")
@Override
public void testSetLicenses(){
//NOSONAR: no test
}

@Test
@Ignore("There is no set method to test")
@Override
public void testSetLicensesUnauthenticated(){
//NOSONAR: no test
}

@Test
@Ignore("There is no set method to test")
@Override
public void testSetLicensesUnauthorized(){
//NOSONAR: no test
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package it.de.aservo.confapi.crowd.rest;


import de.aservo.confapi.commons.constants.ConfAPI;
import de.aservo.confapi.commons.model.MailServerSmtpBean;
import it.de.aservo.confapi.commons.rest.ResourceBuilder;
import org.apache.wink.client.ClientResponse;
import org.apache.wink.client.Resource;
import org.junit.Test;

import javax.ws.rs.core.Response;

import static org.junit.Assert.assertEquals;

public class MailServerResourceFuncTest {

@Test
public void testGetMailServerSmtp() {
Resource resource = ResourceBuilder.builder(ConfAPI.MAIL_SERVER + "/" + ConfAPI.MAIL_SERVER_SMTP).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
}

@Test
public void testSetMailServerSmtp() {
Resource resource = ResourceBuilder.builder(ConfAPI.MAIL_SERVER + "/" + ConfAPI.MAIL_SERVER_SMTP).build();
ClientResponse clientResponse = resource.put(MailServerSmtpBean.EXAMPLE_1);
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
assertEquals(MailServerSmtpBean.EXAMPLE_1.getAdminContact(), clientResponse.getEntity(MailServerSmtpBean.class).getAdminContact());
assertEquals(MailServerSmtpBean.EXAMPLE_1.getPrefix(), clientResponse.getEntity(MailServerSmtpBean.class).getPrefix());
assertEquals(MailServerSmtpBean.EXAMPLE_1.getFrom(), clientResponse.getEntity(MailServerSmtpBean.class).getFrom());
assertEquals(MailServerSmtpBean.EXAMPLE_1.getUseTls(), clientResponse.getEntity(MailServerSmtpBean.class).getUseTls());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package it.de.aservo.confapi.crowd.rest;


import de.aservo.confapi.commons.constants.ConfAPI;
import de.aservo.confapi.commons.model.SettingsBean;
import de.aservo.confapi.crowd.model.SettingsBrandingLoginPageBean;
import it.de.aservo.confapi.commons.rest.ResourceBuilder;
import org.apache.wink.client.ClientResponse;
import org.apache.wink.client.Resource;
import org.junit.Test;

import javax.ws.rs.core.Response;

import static org.junit.Assert.assertEquals;


public class SettingsBrandingResourceFuncTest {

@Test
public void testGetLoginPage() {
Resource resource = ResourceBuilder.builder(ConfAPI.SETTINGS + "/" + ConfAPI.SETTINGS_BRANDING + "/" + ConfAPI.SETTINGS_BRANDING_LOGIN_PAGE).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
assertEquals(SettingsBrandingLoginPageBean.EXAMPLE_2, clientResponse.getEntity(SettingsBrandingLoginPageBean.class));
}

@Test
public void testGetSettings() {
Resource resource = ResourceBuilder.builder(ConfAPI.SETTINGS).build();
ClientResponse clientResponse = resource.get();
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
assertEquals(SettingsBean.EXAMPLE_1.getBaseUrl(), clientResponse.getEntity(SettingsBean.class).getBaseUrl());
assertEquals(SettingsBean.EXAMPLE_1.getTitle(), clientResponse.getEntity(SettingsBean.class).getTitle());
}

@Test
public void testPutLoginPage () { // TODO
Resource resource = ResourceBuilder.builder(ConfAPI.SETTINGS + "/" + ConfAPI.SETTINGS_BRANDING + "/" + ConfAPI.SETTINGS_BRANDING_LOGIN_PAGE).build();
ClientResponse clientResponse = resource.put(SettingsBrandingLoginPageBean.EXAMPLE_2);
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
}

@Test
public void testPutSettings () { // TODO
Resource resource = ResourceBuilder.builder(ConfAPI.SETTINGS).build();
ClientResponse clientResponse = resource.put(SettingsBean.EXAMPLE_1);
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatusCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.de.aservo.confapi.crowd.rest;


import de.aservo.confapi.commons.model.SettingsBean;
import it.de.aservo.confapi.commons.rest.AbstractSettingsResourceFuncTest;

import java.net.URI;


public class SettingsResourceFuncTest extends AbstractSettingsResourceFuncTest {

@Override
protected SettingsBean getExampleBean() {
SettingsBean settingsBean = new SettingsBean();
settingsBean.setTitle("Example");
settingsBean.setBaseUrl(URI.create("https://example.com"));
return settingsBean;
}
}