/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2022, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.as.test.clustering.cluster.cdi;

import org.infinispan.protostream.SerializationContextInitializer;
import org.infinispan.transaction.TransactionMode;
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.as.test.clustering.ClusterTestUtil;
import org.jboss.as.test.clustering.cluster.cdi.webapp.IncrementorBean;
import org.jboss.as.test.clustering.cluster.cdi.webapp.CDISerializationContextInitializer;
import org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor;
import org.jboss.as.test.clustering.cluster.web.AbstractWebFailoverTestCase;
import org.jboss.as.test.clustering.single.web.Mutable;
import org.jboss.as.test.clustering.single.web.SimpleServlet;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;

/**
 * Test failover with CDI session scoped bean using ProtoStream.
 *
 * @author Paul Ferraro
 */
@RunWith(Arquillian.class)
public class ProtoStreamCDIFailoverTestCase extends AbstractWebFailoverTestCase {

    private static final String MODULE_NAME = CDIFailoverTestCase.class.getSimpleName();
    private static final String DEPLOYMENT_NAME = MODULE_NAME + ".war";

    public ProtoStreamCDIFailoverTestCase() {
        super(DEPLOYMENT_NAME, TransactionMode.TRANSACTIONAL);
    }

    @Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
    @TargetsContainer(NODE_1)
    public static Archive<?> deployment1() {
        return createDeployment();
    }

    @Deployment(name = DEPLOYMENT_2, managed = false, testable = false)
    @TargetsContainer(NODE_2)
    public static Archive<?> deployment2() {
        return createDeployment();
    }

    @Deployment(name = DEPLOYMENT_3, managed = false, testable = false)
    @TargetsContainer(NODE_3)
    public static Archive<?> deployment3() {
        return createDeployment();
    }

    private static Archive<?> createDeployment() {
        WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME);
        war.addPackage(IncrementorBean.class.getPackage());
        war.addClasses(Incrementor.class, SimpleServlet.class, Mutable.class);
        ClusterTestUtil.addTopologyListenerDependencies(war);
        war.setWebXML(CDIFailoverTestCase.class.getPackage(), "web.xml");
        war.addAsWebInfResource(CDIFailoverTestCase.class.getPackage(), "distributable-web.xml", "distributable-web.xml");
        war.addAsServiceProvider(SerializationContextInitializer.class.getName(), CDISerializationContextInitializer.class.getName() + "Impl");
        return war;
    }
}

@@ -1926,16 +1926,72 @@
 nkWrap;%0A
+import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;%0A
 import o
@@ -2427,16 +2427,92 @@
 E_NAME +
+ %22.ear%22;%0A    private static final String WEB_DEPLOYMENT_NAME = MODULE_NAME +
  %22.war%22;
@@ -2588,16 +2588,44 @@
 ENT_NAME
+ + '.' + WEB_DEPLOYMENT_NAME
 , Transa
@@ -3336,16 +3336,20 @@
 .class, 
+WEB_
 DEPLOYME
@@ -3896,24 +3896,147 @@
  + %22Impl%22);%0A
+        EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, DEPLOYMENT_NAME);%0A        ear.addAsModule(war);%0A
         retu
@@ -4038,17 +4038,17 @@
  return 
-w
+e
 ar;%0A    

Update ProtoStreamCDIFailoverTestCase to validate EAR deployment.