Skip to content

Instantly share code, notes, and snippets.

@smiklosovic
Created November 5, 2013 14:26
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/22f530928bf04a9deee8 to your computer and use it in GitHub Desktop.
Save smiklosovic/22f530928bf04a9deee8 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 javax.inject.Inject;
import org.jboss.aerogear.security.auth.AuthenticationManager;
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.aerogear.shortener.users.ShortenerUser;
import org.jboss.arquillian.container.test.api.Deployment;
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.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.picketlink.idm.model.basic.Agent;
/**
* @author <a href="mailto:smikloso@redhat.com">Stefan Miklosovic</a>
*
*/
@RunWith(Arquillian.class)
public class ShortenerDaoTestCase {
@Deployment(testable = true)
@TargetsContainer("jbossas")
public static WebArchive getDeployment() {
return Deployments.getDeployment();
}
@Inject
private LinkDao linkDao;
@Inject
private AuthenticationManager<Agent> authenticationManager;
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
@InSequence(1)
@UsingDataSet("datasets/added-links.yml")
@Transactional
public void getClicksByIdAsAdmin() {
ShortenerUser user = AuthenticationUtils.getUser("admin", "123");
authenticationManager.login(user, user.getPassword());
Assert.assertEquals(0, linkDao.getClicksById(new Long(1)));
authenticationManager.logout();
}
@Test
@InSequence(2)
@UsingDataSet("datasets/added-links.yml")
@Transactional
public void getClicksByIdAsNotAuthorized() {
exception.expect(AeroGearSecurityException.class);
Assert.assertEquals(0, linkDao.getClicksById(new Long(1)));
}
}
@bartoszmajsak
Copy link

@UsingDataSet implies @transactional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment