EAD: Configuration error while running tests

Asked

Viewed 83 times

2

I downloaded the videos from the site for studies, in the video of Modulo3_video3, about Configuration, I got an error running the test after using the Configuration feature.

1 - I added the file src main Resources inscription.properties

capacidade.turma = 5

2 - I created the class: Inscricaoconfig

import br.gov.frameworkdemoiselle.configuration.Configuration;

@Configuration(resource = "inscricao")
public class InscricaoConfig {
    private int capacidadeTurma;

    public int getCapacidadeTurma() {
        return capacidadeTurma;
    }
}

3 - I modified the class Class:

@Inject
    private InscricaoConfig config;

    public void matricular(String nome) {
        if (estaMatriculado(nome) || alunosMatriculados.size()==config.getCapacidadeTurma())
            throw new TurmaException();

        alunosMatriculados.add(nome);
        logger.info(bundle.getString("matricula.sucesso", nome));
    }

While running the test with Junit, an error occurred, following stackTrace:

br.com.djsystem.inscricao.exception.TurmaException
    at br.com.djsystem.inscricao.Turma.matricular(Turma.java:31)
    at br.com.djsystem.inscricao.Turma$Proxy$_$$_WeldSubclass.matricular(Turma$Proxy$_$$_WeldSubclass.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:84)
    at org.jboss.weld.interceptor.proxy.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:127)
    at br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor.manage(ExceptionHandlerInterceptor.java:237)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:30)
    at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:68)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:112)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:88)
    at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53)
    at br.com.djsystem.inscricao.Turma$Proxy$_$$_WeldSubclass.matricular(Turma$Proxy$_$$_WeldSubclass.java)
    at br.com.djsystem.inscricao.TurmaTest.matricularAlunoComSucesso(TurmaTest.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at br.gov.frameworkdemoiselle.junit.DemoiselleRunner.runChild(DemoiselleRunner.java:60)
    at br.gov.frameworkdemoiselle.junit.DemoiselleRunner.runChild(DemoiselleRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at br.gov.frameworkdemoiselle.junit.DemoiselleRunner.run(DemoiselleRunner.java:73)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  • What exactly did you modify in the Class? Could you show what the class was like before the modification?

1 answer

1


According to the Demoiselle reference 2.4.2:

Starting from version 2.4.0 (...) the parameters will be searched exactly as they were defined in the configuration class.

Therefore, the configuration class is looking for a key capacidadeTurma in your properties file. So that the configuration class accepts the key capacidade.turma, write down your attribute with @Name:

@Configuration(resource = "inscricao")
public class InscricaoConfig {
    @Name("capacidade.turma")
    private int capacidadeTurma;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.