使用junit

时间:2017-12-07 11:37:54

标签: junit applicationcontext

这里有新人,所以我试图测试我的数据库中某些元素的持久性是否完全使用。这些元素存在于excel文件中。到目前为止我已经尝试过了。并且我一直有相同的应用程序上下文加载失败问题

`@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@TransactionConfiguration(defaultRollback = true)
@ContextConfiguration(
        {   "/applicationContext1.xml",
            "file:C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/src/main/resources/META-INF/spring/applicationContext-security.xml",
            "file:C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/src/main/resources/META-INF/spring/applicationContext-jpa.xml",
        }
        )
public class TestCase {

    @Autowired
    PerimetreComposantService perimetreComposantService; 

    @Test
    public void testSavePerimetreComposant() throws IOException {

        try {
            String content = readFile("C:/Users/Mohammed.yasserdahbi/Desktop/test.txt");
            String[] parts=content.split("@@@@");
            long id =Long.parseLong(parts[1]);

            FileInputStream inputStream = new FileInputStream(new File("C:/Users/Mohammed.yasserdahbi/Desktop/aa.xlsx"));
            ArrayList<String> values = new ArrayList<String>();
            List<Article> articles =new ArrayList();
            Workbook workbook = new XSSFWorkbook(inputStream);
            Sheet firstSheet = workbook.getSheetAt(9);
            Iterator<Row> iterator = firstSheet.iterator();
            while (iterator.hasNext()) {
                Row nextRow = iterator.next();
                Iterator<Cell> cellIterator = nextRow.cellIterator();
                if (nextRow.getRowNum() == 0 || nextRow.getRowNum() == 1) {
                    /*
                     *   Do Nothing
                     */
                }
                else {
                    Cell cell;
                    /* For each row, iterate through each columns */
                    for (int i = 0; i < 5; i++) {

                        /*
                         * Get the cell content including the blank cells
                         */
                        cell = nextRow.getCell(i, Row.CREATE_NULL_AS_BLANK);
                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_STRING:
                        values.add(cell.getStringCellValue());
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        values.add(Integer.toString((int) cell
                                .getNumericCellValue()));
                        break;
                    case Cell.CELL_TYPE_BOOLEAN:
                        values.add(Boolean.toString((boolean) cell
                                .getBooleanCellValue()));
                        break;
                    /*
                     * When it's a blank cell, fill it with empty string
                     */
                    case Cell.CELL_TYPE_BLANK:
                        values.add("");
                        break;
                    default:
                        values.add(cell.getStringCellValue());
                    }

                }
                    try{
                        System.out.println("toto");
                        articles = perimetreComposantService.findArticlesBy(values.get(0), values.get(1), Double.parseDouble(values.get(2)), Integer.parseInt(values.get(3)), values.get(4), id);

                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                assertFalse(!articles.isEmpty());
                }
            }
            }
             catch (Exception e) {
            e.printStackTrace();
        }

    }`

失败详情:

  

2017-12-08 11:42:30 [INFO]   (XmlBeanDefinitionReader.java:loadBeanDefinitions:315)=&gt;加载XML   来自URL的bean定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/classes/META-INF/spring/applicationContext.xml]   2017-12-08 11:42:31 [INFO]   (XmlBeanDefinitionReader.java:loadBeanDefinitions:315)=&gt;加载XML   来自URL的bean定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/test-classes/applicationContext1.xml]   2017-12-08 11:42:31 [INFO]   (DefaultListableBeanFactory.java:registerBeanDefinition:665)=&gt;   覆盖bean的数据源定义&#39;:替换[Generic   bean:class [org.apache.commons.dbcp.BasicDataSource];范围=;   抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0;   autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL;   factoryMethodName = NULL; initMethodName = NULL; destroyMethodName =关闭;   在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/classes/META-INF/spring/applicationContext.xml]]   [Generic bean:class [org.apache.commons.dbcp.BasicDataSource];   范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0;   dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE;   factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL;   destroyMethodName =关闭;在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/test-classes/applicationContext1.xml]]   2017-12-08 11:42:31 [INFO]   (DefaultListableBeanFactory.java:registerBeanDefinition:665)=&gt;   覆盖bean的事务bean定义&#39; transactionManager&#39;:替换   [通用豆类:类   [org.springframework.orm.jpa.JpaTransactionManager];范围=;   抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0;   autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL;   factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = NULL;   在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/classes/META-INF/spring/applicationContext.xml]]   用[Generic bean:class   [org.springframework.orm.jpa.JpaTransactionManager];范围=;   抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0;   autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL;   factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = NULL;   在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/test-classes/applicationContext1.xml]]   2017-12-08 11:42:31 [INFO]   (DefaultListableBeanFactory.java:registerBeanDefinition:665)=&gt;   覆盖bean的#bean; viewResolver&#39;:替换[Generic   bean:class   [org.springframework.web.servlet.view.UrlBasedViewResolver];范围=;   抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0;   autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL;   factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = NULL;   在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/classes/META-INF/spring/applicationContext.xml]]   用[Generic bean:class   [org.springframework.web.servlet.view.UrlBasedViewResolver];范围=;   抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0;   autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL;   factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = NULL;   在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/test-classes/applicationContext1.xml]]   2017-12-08 11:42:31 [INFO]   (DefaultListableBeanFactory.java:registerBeanDefinition:665)=&gt;   覆盖bean的实体bean定义&#39; entityManagerFactory&#39;:替换   [通用豆类:类   [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean];   范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0;   dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE;   factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL;   destroyMethodName = NULL;在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/classes/META-INF/spring/applicationContext.xml]]   用[Generic bean:class   [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean];   范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 0;   dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE;   factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL;   destroyMethodName = NULL;在URL中定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/test-classes/applicationContext1.xml]]   2017-12-08 11:42:31 [INFO]   (XmlBeanDefinitionReader.java:loadBeanDefinitions:315)=&gt;加载XML   来自URL的bean定义   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/classes/META-INF/spring/applicationContext-jpa.xml]   2017-12-08 11:42:31 [错误]   (TestContextManager.java:prepareTestInstance:314)=&gt;抓到了异常   同时允许TestExecutionListener   [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5c8c05]   准备测试实例   [com.zodiac.apcit.business.test.TestCase2@1ecade2]   java.lang.IllegalStateException:无法加载ApplicationContext   org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)     在   org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)     在   org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)     在   org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)     在   org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)     在   org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)at   org.springframework.test.context.junit4.SpringJUnit4ClassRunner $ 1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)     在   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)     在   org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)     在   org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)     在   org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:238)at   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63)at   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)at at   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)at at   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)at at   org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)     在   org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)     在org.junit.runners.ParentRunner.run(ParentRunner.java:309)at   org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)     在   org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)     在   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)   引起:   org.springframework.beans.factory.BeanDefinitionStoreException:   从URL解析XML文档时出现意外异常   [文件:/ C:/Users/Mohammed.yasserdahbi/Desktop/Workspace/APCITA380/target/classes/META-INF/spring/applicationContext-jpa.xml];   嵌套异常是org.springframework.beans.FatalBeanException:   NamespaceHandler类无效   [org.springframework.data.jpa.repository.config.JpaRepositoryNameSpaceHandler]   for namespace [http://www.springframework.org/schema/data/jpa]:   处理程序类文件或依赖类的问题;嵌套异常   是java.lang.NoClassDefFoundError:   org / springframework / beans / factory / xml / NamespaceHandlerSupport at   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)     在   org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)     在   org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:233)     在   org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:117)     在   org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)     在   org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)     在   org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)     在   org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)     在   org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)     ... 25更多引起:org.springframework.beans.FatalBeanException:   NamespaceHandler类无效   [org.springframework.data.jpa.repository.config.JpaRepositoryNameSpaceHandler]   for namespace [http://www.springframework.org/schema/data/jpa]:   处理程序类文件或依赖类的问题;嵌套异常   是java.lang.NoClassDefFoundError:   org / springframework / beans / factory / xml / NamespaceHandlerSupport at   org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:139)     在   org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1433)     在   org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)     在   org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:195)     在   org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)     在   org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)     ... 38更多引起:java.lang.NoClassDefFoundError:   org / springframework / beans / factory / xml / NamespaceHandlerSupport at   java.lang.ClassLoader.findBootstrapClass(Native Method)at   java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1061)     在java.lang.ClassLoader.loadClass(ClassLoader.java:412)at   java.lang.ClassLoader.loadClass(ClassLoader.java:410)at   sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)at at   java.lang.ClassLoader.loadClass(ClassLoader.java:356)at   org.springframework.util.ClassUtils.forName(ClassUtils.java:257)at   org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:124)     ......还有45个

任何人都可以说出问题是什么?

0 个答案:

没有答案