Giter Site home page Giter Site logo

cdi-unit's Introduction

cdi-unit

Unit testing for CDI applications. Supports Mockito for mocking dependencies.

See website for full details http://cdi-unit.github.io/cdi-unit

Discussion can be found here https://groups.google.com/forum/#!forum/cdi-unit

Maven Central

<dependency>
  <groupId>org.jglue.cdi-unit</groupId>
  <artifactId>cdi-unit</artifactId>
  <version>${cdi-unit-version}</version>
  <scope>test</scope>
</dependency>
class Starship {
 
  @Inject
  Engine engine; //We don't know the exact engine that this ship will have.
 
  void start() {
    engine.start();
  }
}

@RunWith(CdiRunner.class)
@AdditionalClasses(WarpDrive.class) // WarpDrive is available to use.
class TestStarship {
 
  @Inject
  Starship starship;
 
  @Test
  public void testStart() {
    starship.start(); // Going to warp!
  }
}

Acknowledgements

This project uses code shamelessly copied from:

Mockrunner under Apache license. Resteasy under Apache license.

License

Copyright 2013 Bryn Cooke

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.

cdi-unit's People

Contributors

alien0matic avatar aschoerk avatar brunoessmann avatar bryncooke avatar cschroeder0303 avatar dastrobu avatar dependabot[bot] avatar gmahieux avatar ikysil avatar itsmeden avatar kalgon avatar kdubb avatar lastnico avatar mamohr avatar nicolassfpd avatar pa314159 avatar pcasaes avatar seanf avatar serprime avatar sparty02 avatar sventorben avatar

cdi-unit's Issues

Cannot inject beans from external jars when using symbolic link or relative paths as MAVEN_REPO location

I believe this issue is the same as this one from original repo:
cdi-unit#151

My setup:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Java version: 11.0.8, vendor: N/A, runtime: /usr/local/java/java-11-openjdk-11.0.8.10-0.portable.jdk.el.x86_64
Default locale: en_US, platform encoding: ISO-8859-1
OS name: "linux", version: "5.10.22-200.fc33.x86_64", arch: "amd64", family: "unix"`

Way to create the issue:

Have 2 projects:

  • Project A containing
    • CDI bean MyBean.java
    • empty META-INF/beans.xml
  • Project B having a dependency on Project A and containing
    • Unit test MyTest with @RunWith(CdiRunner.class) and doing @Inject of MyBean

Setup a symbolic link that goes to your maven repository, let's call it MAVEN_REPO_SYMLINK

Execute test from Project B with maven command

mvn test -Dtest=MyTest -Dmaven.repo.local=MAVEN_REPO_SYMLINK

In my actual case:

  • the injected bean is called PreprocessingRule which is contained in globalCareer-services-green-feat-NA-343_java11-SNAPSHOT.jar
  • the test is named AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest.
  • My MAVEN_REPO:
    • /home/lamni/development/MAVEN_REPO without symlink or relative paths ./ | ../
    • /home/lamni/./development/M2_REPO using both relative path ./ and symlink M2_REPO going to MAVEN_REPO

When running mvn command without symlink, it works properly
mvn test -Dtest='AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest#pensionInsuranceWithNoRegulIn2012_noAdaptation' -Dmaven.repo.local=/home/lamni/development/MAVEN_REPO

But when using the symlink and or relative paths, like this:
mvn test -Dtest='AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest#pensionInsuranceWithNoRegulIn2012_noAdaptation' -Dmaven.repo.local=/home/lamni/./development/M2_REPO

It leads to issues like the extract below:

[INFO] Running be.sfpd.atca.amount.calculation.rules.preprocessing.qualitycodeandregultypeadaptations.AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest
2021-03-25 17:35:14,010 DEBUG [main] internal.WeldTestUrlDeployment (WeldTestUrlDeployment.java:411) - CDI classpath entries discovered:
...
2021-03-25 17:35:14,022 DEBUG [main] internal.WeldTestUrlDeployment (WeldTestUrlDeployment.java:413) - file:/home/lamni/development/MAVEN_REPO/be/rvponp/globalCareer-services/green-feat-NA-343_java11-SNAPSHOT/globalCareer-services-green-feat-NA-343_java11-SNAPSHOT.jar
...
2021-03-25 17:35:14,090 DEBUG [main] internal.WeldTestUrlDeployment (WeldTestUrlDeployment.java:276) - CDI-Unit discovered:
2021-03-25 17:35:14,090 DEBUG [main] internal.WeldTestUrlDeployment (WeldTestUrlDeployment.java:279) - be.sfpd.atca.amount.calculation.rules.preprocessing.qualitycodeandregultypeadaptations.AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.793 s <<< FAILURE! - in be.sfpd.atca.amount.calculation.rules.preprocessing.qualitycodeandregultypeadaptations.AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest
[ERROR] pensionInsuranceWithNoRegulIn2012_noAdaptation(be.sfpd.atca.amount.calculation.rules.preprocessing.qualitycodeandregultypeadaptations.AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest)  Time elapsed: 0.008 s  <<< ERROR!
org.jboss.weld.exceptions.DeploymentException: 
WELD-001408: Unsatisfied dependencies for type PreprocessingRule with qualifiers @Default
  at injection point [UnbackedAnnotatedField] @Inject private be.sfpd.atca.amount.calculation.rules.preprocessing.qualitycodeandregultypeadaptations.AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest.rule
  at be.sfpd.atca.amount.calculation.rules.preprocessing.qualitycodeandregultypeadaptations.AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest.rule(AdaptationsForQualityCodeAndTypeRegulPensionInsuranceTest.java:0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.