LinkedHashMap问题......任何人帮助我

时间:2015-10-14 09:55:42

标签: groovy

在执行此测试用例时,遇到错误我正面临...... 请有人建议我克服这个问题。

AbortedJobImportTest 


testAbortedJobAddedSuccessfullyToExcludedRun    


Unknown entity: java.util.LinkedHashMap 
org.hibernate.MappingException: Unknown entity: java.util.LinkedHashMap
    at com.rsa.test.crawler.CrawlerTestBase.setUp(CrawlerTestBase.groovy:42)
    at com.rsa.test.crawler.AbortedJobImportTest.setUp(AbortedJobImportTest.groovy:19)

/ *
        ***

CrawlerTestBase

    public class CrawlerTestBase extends GroovyTestCase {
        static transactional = false;
        def productsModel;
        protected JenkinsJobCrawlerDTO jenkinsCrawlerDTO;
        def jenkinsJobService; 
        def httpClientService;
        def sessionFactory;
        def productModelsService;
        protected String JENKINS_URL = "http://10.101.43.253:8080/jenkins/";
        protected String JENKINS_JOB_CONSTANT= "job";
        protected String JUNIT_TEST_PARAMETERS = "type=junit";
        protected String CUSTOM_JUNIT_SELENIUM_TEST_PARAMETERS = "type=selenium,outputfile=Custom-junit-report*";
        protected String DEFAULT_PRODUCT = "AM";

        public void setUp(){
            deleteDataFromTables();
            Date date = new Date();

            productsModel = new ProductModel(product:DEFAULT_PRODUCT,jenkinsServers:"10.101.43.253",date:date);
            if (productsModel.validate()) {
                productsModel.save(flush:true);
                log.info("Added entry for prodct model for "+DEFAULT_PRODUCT);
            }
            else {
                productsModel.errors.allErrors.each { log.error it }
            }
            jenkinsCrawlerDTO = new JenkinsJobCrawlerDTO();
            productModelsService.reinitialise();
            sessionFactory.currentSession.save(flush:true);
            sessionFactory.currentSession.clear();
        }

        public void tearDown(){
            deleteDataFromTables();
        }

        protected void deleteDataFromTables(){
            Set<String> tablesToDeleteData = new HashSet<String>();
            tablesToDeleteData.add("ExcludedJenkinsRuns");
            tablesToDeleteData.add("TestRuns");
            tablesToDeleteData.add("ProductModel");
            tablesToDeleteData.add("SystemEvents");
            tablesToDeleteData.add("JenkinsJobsToCrawl");
            tablesToDeleteData.add("TestSuitesInViewList");
            tablesToDeleteData.add("JenkinsJobsToCrawl");
            (ApplicationHolder.application.getArtefacts("Domain") as List).each {
                  if(tablesToDeleteData.contains(it.getName())){
                      log.info("Deleting data from ${it.getName()}");
                      it.newInstance().list()*.delete()  
                  }

            }
            sessionFactory.currentSession.flush();
            sessionFactory.currentSession.clear();
        }

        public void oneTimeSetUp(){

        }

        public void oneTimeTearDown(){

        }
    }

AbortedJobImportTest

        public class AbortedJobImportTest extends CrawlerTestBase {
        private String jobUrl = JENKINS_URL+JENKINS_JOB_CONSTANT+"/am-java-source-build/69/";

        @Before
        public void setUp() {
            super.setUp();
            jenkinsCrawlerDTO.setJobUrl(jobUrl);
        }

        @After
        public void cleanup() {
            super.tearDown();
        }

        @Test
        public void testAbortedJobAddedSuccessfullyToExcludedRun() {
            int countBeforeImport = ExcludedJenkinsRuns.count();
            jenkinsJobService.handleTestResults(jobUrl,JUNIT_TEST_PARAMETERS);
            int countAfterImport = ExcludedJenkinsRuns.count();
            Assert.assertEquals(countBeforeImport+1, countAfterImport);
            ExcludedJenkinsRuns excludedRun = ExcludedJenkinsRuns.findByJobNameLike(jenkinsCrawlerDTO.jobName);
            Assert.assertNotNull(excludedRun);
            Assert.assertEquals(jobUrl, excludedRun.jobUrl);
            Assert.assertEquals(jenkinsCrawlerDTO.jobName, excludedRun.jobName);
            Assert.assertEquals(jenkinsCrawlerDTO.jenkinsServer, excludedRun.jenkinsServer);
            Assert.assertEquals(jenkinsCrawlerDTO.buildNumber.toInteger(), excludedRun.buildNumber);
            Assert.assertEquals("Build Aborted", excludedRun.exclusionReason);
        }

    }
*/

我无法弄清楚此代码中的问题。谁能帮我?     在执行此测试用例时,遇到错误我正面临...... 请有人建议我克服这个问题。

1 个答案:

答案 0 :(得分:0)

这意味着您尝试将LinkedHashMap放在Product Model的构造函数中,但没有使用LinkedHashMap参数的构造函数。

我猜问题是你的单元测试。模型构造函数将由grails框架添加。您在单元测试中没有运行grails框架,因为您使用GroovyTestCase而不是Spock。 锁定https://grails.github.io/grails-doc/3.0.5/guide/single.html#unitTesting