/**
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * 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.pnc.coordinator.test;

import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.pnc.model.BuildConfiguration;
import org.jboss.pnc.model.BuildConfigurationSet;
import org.jboss.pnc.model.User;
import org.jboss.pnc.spi.BuildCoordinationStatus;
import org.jboss.pnc.spi.BuildScope;
import org.jboss.pnc.spi.BuildSetStatus;
import org.jboss.pnc.spi.coordinator.BuildCoordinator;
import org.jboss.pnc.spi.coordinator.BuildSetTask;
import org.jboss.pnc.spi.coordinator.BuildTask;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.inject.Inject;
import javax.persistence.PersistenceException;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by <a href="mailto:matejonnet@gmail.com">Matej Lazar</a> on 2014-11-23.
 */
@RunWith(Arquillian.class)
public class ConfigurationsTest extends ProjectBuilder {

    @Inject
    BuildCoordinator buildCoordinator;

    @Test(expected=PersistenceException.class) //TODO test is not run as expected exception is thrown configurationBuilder.build...
    @InSequence(10)
    public void dependsOnItselfConfigurationTestCase() throws Exception {

        BuildConfiguration buildConfiguration = configurationBuilder.buildConfigurationWhichDependsOnItself();

        User user = User.Builder.newBuilder().id(1).build();

        BuildSetTask taskSet = buildCoordinator.build(buildConfiguration, user, BuildScope.SINGLE, false);
        Set<BuildTask> buildTasks = taskSet.getBuildTasks();
        assertThat(buildTasks).hasSize(1);
        BuildTask buildTask = buildTasks.iterator().next();
        Assert.assertEquals(BuildCoordinationStatus.REJECTED, buildTask.getStatus());
        Assert.assertTrue("Invalid status description: " + buildTask.getStatusDescription(), buildTask.getStatusDescription().contains("itself"));
    }

    @Test(expected=PersistenceException.class) //TODO test is not run as expected exception is thrown configurationBuilder.build...
    @InSequence(15)
    public void cycleConfigurationTestCase() throws Exception {
 
        BuildConfigurationSet buildConfigurationSet = configurationBuilder.buildConfigurationSetWithCycleDependency();

        User user = User.Builder.newBuilder().id(1).build();

        BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, user, false, true);
        Assert.assertEquals(BuildSetStatus.REJECTED, buildSetTask.getStatus());
        Assert.assertTrue("Invalid status description: " + buildSetTask.getStatusDescription(), buildSetTask.getStatusDescription().contains("Cycle dependencies found"));
    }

}

@@ -734,24 +734,83 @@
 ator.test;%0A%0A
+import org.jboss.arquillian.container.test.api.Deployment;%0A
 import org.j
@@ -843,16 +843,16 @@
 illian;%0A
-
 import o
@@ -1297,24 +1297,74 @@
 .BuildTask;%0A
+import org.jboss.shrinkwrap.api.spec.JavaArchive;%0A
 import org.j
@@ -1708,16 +1708,16 @@
 .class)%0A
-
 public c
@@ -1762,24 +1762,205 @@
 tBuilder %7B%0A%0A
+    @Deployment%0A    public static JavaArchive createDeployment() %7B%0A        return BuildCoordinatorDeployments.deployment(BuildCoordinatorDeployments.Options.WITH_DATASTORE);%0A    %7D%0A%0A
     @Inject%0A

Add missing deployed that has been removed from the base class.