Skip to content

Instantly share code, notes, and snippets.

@smiklosovic
Created November 4, 2013 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smiklosovic/fe5838598a524afdb775 to your computer and use it in GitHub Desktop.
Save smiklosovic/fe5838598a524afdb775 to your computer and use it in GitHub Desktop.
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.aerogear.shortener.test;
import java.net.URL;
import javax.inject.Inject;
import javax.ws.rs.core.Response.Status;
import org.jboss.aerogear.security.exception.AeroGearSecurityException;
import org.jboss.aerogear.shortener.jpa.dao.LinkDao;
import org.jboss.aerogear.shortener.test.utils.AuthenticationUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.persistence.UsingDataSet;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import com.jayway.restassured.response.Response;
/**
* @author <a href="mailto:smikloso@redhat.com">Stefan Miklosovic</a>
*
*/
@RunWith(Arquillian.class)
public class ShortenerDaoTestCase {
@Deployment
@TargetsContainer("jbossas")
public static WebArchive getDeployment() {
return Deployments.getDeployment();
}
@Inject
private LinkDao linkDao;
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
@InSequence(1)
@RunAsClient
public void login(@ArquillianResource URL root) {
Response loginResponse = AuthenticationUtils.login(
AuthenticationUtils.getAdminLoginName(),
AuthenticationUtils.getAdminPassword(),
root.toExternalForm());
AuthenticationUtils.setAuthCookies(loginResponse.getCookies());
Assert.assertEquals(Status.OK.getStatusCode(), loginResponse.getStatusCode());
}
@Test
@InSequence(2)
@UsingDataSet("datasets/added-links.yml")
@Transactional
public void getCountOfLinksWhenLoggedInAsAdmin() {
Assert.assertEquals(0, linkDao.getClicksById(new Long(1)));
}
@Test
@InSequence(3)
@RunAsClient
public void logout(@ArquillianResource URL root) {
Response logoutResponse = AuthenticationUtils.logout(
AuthenticationUtils.getAuthCookies(),
root.toExternalForm());
Assert.assertEquals(Status.OK.getStatusCode(), logoutResponse.getStatusCode());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment