Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add packages in deployment jar using shrinkWrap in arquillian test

I am using arquillian for unit test. I am creating deployment jar using shrinkWrap. But for that I need to add all the packages which are used in my project, which are a lot in number.

following is my test file

@RunWith(Arquillian.class)
public class GreeterTest {



    @Deployment
    public static JavaArchive createDeployment() throws NamingException {

        return ShrinkWrap.create(JavaArchive.class, "test.jar")
                .addPackage(ABC.class.getPackage())
                .addPackage(EFG.class.getPackage())
                .addPackage(HIJ.class.getPackage())
                .addPackage(KLM.class.getPackage())
                .addPackage(NOP.class.getPackage())
                .addPackage(QRS.class.getPackage())
                .addPackage(TUV.class.getPackage())
                .addPackage(XYZ.class.getPackage())

                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

      }

    @Inject
    ABC abc;

    @Inject
    EFG efg;

    @Inject
    HIJ hij;

    @Inject
    KLM klm;

    @Inject
    NOP nop;

    @Test
    public void shouldBeAbleToInjectEJBAndInvoke() throws Exception {

        abc.getDetail();

    }
}

You can see .addPackage(). there are hundreds of packages in my project. Obvious code size will be increasing enormously

Is there any other way for this? Or I must be making some big mistake

like image 827
nilesh Avatar asked Dec 04 '22 02:12

nilesh


1 Answers

I'd recommend you to use string representation of package path: "com.root.core" etc. And there are methods:

addPackage(String pack)

addPackages(boolean recursive, String... packages)

The latest is more appropriate for you I guess as it provides you a possibility to add packages recursively and thus you avoid repeatedly including every package. For instance:

.addPackages(true, "com.root")
like image 112
Vit Ias Avatar answered Dec 06 '22 19:12

Vit Ias