cz.muni.fi.editor.test.service.organization.OrganizationServiceGetIdIT.java Source code

Java tutorial

Introduction

Here is the source code for cz.muni.fi.editor.test.service.organization.OrganizationServiceGetIdIT.java

Source

/*
*Copyright  2016 Dominik Szalai (emptulik@gmail.com)
*
*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 cz.muni.fi.editor.test.service.organization;

import cz.muni.fi.editor.test.service.support.annotations.IntegrationTest;
import cz.muni.fi.editor.test.service.support.annotations.WithEditorUser;
import lombok.extern.log4j.Log4j2;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by Dominik Szalai - emptulik at gmail.com on 20.10.2016.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@IntegrationTest
@Log4j2
public class OrganizationServiceGetIdIT extends OrganizationServiceIT {

    @Test(expected = IllegalArgumentException.class)
    @WithEditorUser
    public void nullID() {
        organizationService.getById(null);
    }

    // cannot be illegal because if Long is passed
    // it is checked by AOP then passed to accesvoter
    // because user is not member of 1000 denied is thrown
    @Test(expected = AccessDeniedException.class)
    @WithEditorUser
    public void getNotExists() {
        organizationService.getById(Long.valueOf(1000L));
    }

    @Test(expected = AccessDeniedException.class)
    @WithEditorUser(8L)
    public void getDenied() {
        organizationService.getById(1L);
    }

    @Test
    @WithEditorUser(3L)
    public void getValid() {
        Assert.assertEquals(Long.valueOf(3L), organizationService.getById(3L).getId());
    }

    @Test(expected = AccessDeniedException.class)
    @WithEditorUser(8L)
    public void getUnapproved() {
        organizationService.getById(5L);
    }
}