Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'restcomm-1543' of https://github.com/RestComm/Restcomm-…
…Connect into restcomm-1543
- Loading branch information
Showing
4 changed files
with
480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
...omm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/ProfilesEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package org.restcomm.connect.testsuite.http; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.net.URL; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.jboss.arquillian.container.test.api.Deployer; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.shrinkwrap.resolver.api.maven.archive.ShrinkWrapMaven; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
import org.restcomm.connect.commons.Version; | ||
import org.restcomm.connect.commons.annotations.FeatureExpTests; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.sun.jersey.api.client.ClientResponse; | ||
|
||
/** | ||
* @author maria | ||
*/ | ||
|
||
@RunWith(Arquillian.class) | ||
public class ProfilesEndpointTest extends EndpointTest { | ||
private final static Logger logger = Logger.getLogger(ProfilesEndpointTest.class.getName()); | ||
|
||
private static final String version = Version.getVersion(); | ||
|
||
@ArquillianResource | ||
private Deployer deployer; | ||
@ArquillianResource | ||
URL deploymentUrl; | ||
|
||
//super admin account | ||
private String superAdminAccountSid = "ACae6e420f425248d6a26948c17a9e2acf"; | ||
private String superAdminAuthToken = "77f8c12cc7b8f8423e5c38b035249166"; | ||
|
||
//admin account | ||
private String adminAccountSid = "AC574d775522c96f9aacacc5ca60c8c74g"; | ||
private String adminAuthToken = "77f8c12cc7b8f8423e5c38b035249166"; | ||
|
||
//developer account | ||
private String devAccountSid = "AC574d775522c96f9aacacc5ca60c8c74f"; | ||
private String devAuthToken = "77f8c12cc7b8f8423e5c38b035249166"; | ||
|
||
private final String profileSid = "PRafbe225ad37541eba518a74248f0ac4c"; | ||
|
||
JsonObject profileDocument; | ||
JsonObject updatedProfileDocument; | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
} | ||
|
||
/** | ||
* SuperAdmin is allowed to read any profile | ||
* this test will try to Read single profile | ||
*/ | ||
@Test | ||
public void getProfile(){ | ||
JsonObject profileJsonObject = RestcommProfilesTool.getInstance().getProfile(deploymentUrl.toString(), superAdminAccountSid, superAdminAuthToken, profileSid); | ||
assertNotNull(profileJsonObject); | ||
logger.info("profile: "+profileJsonObject); | ||
// TODO Read and verify further response | ||
} | ||
|
||
/** | ||
* getProfileList | ||
*/ | ||
@Test | ||
public void getProfileList(){ | ||
JsonArray jsonArray = null; | ||
jsonArray = RestcommProfilesTool.getInstance().getProfileListJsonResponse(deploymentUrl.toString(), superAdminAccountSid, superAdminAuthToken); | ||
logger.info("profile list: "+jsonArray); | ||
assertNotNull(jsonArray); | ||
assertEquals(0,jsonArray.size()); | ||
// TODO Add default list in DB script, Read and verify further response | ||
} | ||
|
||
/** | ||
* Administrators can not read profile | ||
*/ | ||
@Test | ||
@Category(FeatureExpTests.class) | ||
public void getProfileFromAdministratorAccount(){ | ||
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), adminAccountSid, adminAuthToken, profileSid); | ||
assertNotNull(clientResponse); | ||
logger.info("profile: "+clientResponse); | ||
assertEquals(403, clientResponse.getStatus()); | ||
|
||
} | ||
/** | ||
* Developers can not read profile | ||
*/ | ||
@Test | ||
@Category(FeatureExpTests.class) | ||
public void getProfileFromDeveloperAccount(){ | ||
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), devAccountSid, devAuthToken, profileSid); | ||
assertNotNull(clientResponse); | ||
logger.info("profile: "+clientResponse); | ||
assertEquals(403, clientResponse.getStatus()); | ||
|
||
} | ||
|
||
/** | ||
* createProfileTest | ||
* only super admin can create a new profile | ||
*/ | ||
@Test | ||
public void createProfileTest(){ | ||
//super admin tries to create profile | ||
ClientResponse clientResponse = RestcommProfilesTool.getInstance().createProfileResponse(deploymentUrl.toString(), superAdminAccountSid, superAdminAuthToken, profileDocument); | ||
logger.info("clientResponse: "+clientResponse); | ||
assertEquals(200, clientResponse.getStatus()); | ||
|
||
// TODO Read and verify further response | ||
} | ||
|
||
/** | ||
* updateProfileTest | ||
*/ | ||
@Test | ||
public void updateProfileTest(){ | ||
//super admin tries to update profile | ||
ClientResponse clientResponse = RestcommProfilesTool.getInstance().updateProfileResponse(deploymentUrl.toString(), superAdminAccountSid, superAdminAuthToken, profileSid, updatedProfileDocument); | ||
logger.info("clientResponse: "+clientResponse); | ||
assertEquals(200, clientResponse.getStatus()); | ||
|
||
// TODO Read and verify further response | ||
} | ||
|
||
/** | ||
* deleteProfileTest | ||
*/ | ||
@Test | ||
public void deleteProfileTest(){ | ||
//super admin tries to delete profile | ||
ClientResponse clientResponse = RestcommProfilesTool.getInstance().deleteProfileResponse(deploymentUrl.toString(), superAdminAccountSid, superAdminAuthToken, profileSid); | ||
logger.info("clientResponse: "+clientResponse); | ||
assertEquals(200, clientResponse.getStatus()); | ||
|
||
// TODO Read and verify further response | ||
} | ||
|
||
@Test | ||
@Category(FeatureExpTests.class) | ||
public void createProfilePermissionTest(){ | ||
//admin tries to create profile | ||
ClientResponse clientResponse = RestcommProfilesTool.getInstance().createProfileResponse(deploymentUrl.toString(), adminAccountSid, adminAuthToken, profileDocument); | ||
logger.info("clientResponse: "+clientResponse); | ||
assertTrue(clientResponse.getStatus() == 403); | ||
//developer tries to create profile | ||
clientResponse = RestcommProfilesTool.getInstance().createProfileResponse(deploymentUrl.toString(), devAccountSid, devAuthToken, profileDocument); | ||
logger.info("clientResponse: "+clientResponse); | ||
assertTrue(clientResponse.getStatus() == 403); | ||
} | ||
|
||
@Deployment(name = "ProfilesEndpointTest", managed = true, testable = false) | ||
public static WebArchive createWebArchiveNoGw() { | ||
logger.info("Packaging Test App"); | ||
logger.info("version"); | ||
WebArchive archive = ShrinkWrap.create(WebArchive.class, "restcomm.war"); | ||
final WebArchive restcommArchive = ShrinkWrapMaven.resolver() | ||
.resolve("org.restcomm:restcomm-connect.application:war:" + version).withoutTransitivity() | ||
.asSingle(WebArchive.class); | ||
archive = archive.merge(restcommArchive); | ||
archive.delete("/WEB-INF/sip.xml"); | ||
archive.delete("/WEB-INF/conf/restcomm.xml"); | ||
archive.delete("/WEB-INF/data/hsql/restcomm.script"); | ||
archive.addAsWebInfResource("sip.xml"); | ||
archive.addAsWebInfResource("restcomm.xml", "conf/restcomm.xml"); | ||
archive.addAsWebInfResource("restcomm.script_accounts_test", "data/hsql/restcomm.script"); | ||
logger.info("Packaged Test App"); | ||
return archive; | ||
} | ||
|
||
} |
Oops, something went wrong.