+++ /dev/null
-/*\r
- * Copyright (C) 2007-2012 Mathieu Baudier\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.hibernate.process;\r
-\r
-import java.sql.SQLException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.argeo.slc.dao.process.SlcExecutionDao;\r
-import org.argeo.slc.hibernate.unit.HibernateTestCase;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-import org.argeo.slc.unit.process.SlcExecutionTestUtils;\r
-import org.hibernate.HibernateException;\r
-import org.hibernate.Session;\r
-import org.springframework.orm.hibernate3.HibernateCallback;\r
-\r
-public class SlcExecutionHibernateTest extends HibernateTestCase {\r
-\r
- public void testSave() {\r
- SlcExecutionDao dao = getBean(SlcExecutionDao.class);\r
-\r
- SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();\r
- slcExec.getSteps().add(new SlcExecutionStep("A log line"));\r
- slcExec.getSteps().add(new SlcExecutionStep("Two log\nlines"));\r
-\r
- dao.create(slcExec);\r
-\r
- SlcExecution slcExecPersisted = dao.getSlcExecution(slcExec.getUuid());\r
- assertSlcExecution(slcExec, slcExecPersisted);\r
- }\r
-\r
- public void testTailSteps() {\r
- SlcExecutionDao dao = getBean(SlcExecutionDao.class);\r
-\r
- SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();\r
- int totalStepCount = 20;\r
- for (int i = 0; i < totalStepCount; i++) {\r
- slcExec.getSteps().add(new SlcExecutionStep("Log " + i));\r
- }\r
- dao.create(slcExec);\r
-\r
- int lastStepsCount = 7;\r
- List<SlcExecutionStep> firstSteps = dao.tailSteps(slcExec.getUuid(),\r
- lastStepsCount);\r
- assertEquals(lastStepsCount, firstSteps.size());\r
-\r
- SlcExecutionStep lastStep = firstSteps.get(lastStepsCount - 1);\r
-\r
- List<SlcExecutionStep> additionalSteps = new ArrayList<SlcExecutionStep>();\r
- int additionalStepsCount = 13;\r
- for (int i = 0; i < additionalStepsCount; i++) {\r
- additionalSteps.add(new SlcExecutionStep("Additonal log " + i));\r
- }\r
- dao.addSteps(slcExec.getUuid(), additionalSteps);\r
-\r
- List<SlcExecutionStep> lastSteps = dao.tailSteps(slcExec.getUuid(),\r
- lastStep.getUuid());\r
- assertEquals(additionalStepsCount, lastSteps.size());\r
- }\r
-\r
- public void testModify() {\r
- SlcExecutionDao dao = getBean(SlcExecutionDao.class);\r
-\r
- // slcExecution Creation\r
- SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution();\r
- slcExec.getSteps().add(new SlcExecutionStep("A log line"));\r
- slcExec.getSteps().add(new SlcExecutionStep("Two log\nlines"));\r
-\r
- dao.create(slcExec);\r
-\r
- // slcExecution retrieval and update\r
- final SlcExecution slcExecRetrieved = dao.getSlcExecution(slcExec\r
- .getUuid());\r
-\r
- getHibernateTemplate().execute(new HibernateCallback() {\r
-\r
- public Object doInHibernate(Session session)\r
- throws HibernateException, SQLException {\r
- session.refresh(slcExecRetrieved);\r
- List<String> logLineListStep0 = slcExecRetrieved.getSteps()\r
- .get(0).getLogLines();\r
- for (String logLine : logLineListStep0)\r
- logLine = logLine + "appended Log text";\r
-\r
- slcExecRetrieved.getSteps().get(0)\r
- .setLogLines(logLineListStep0);\r
- slcExecRetrieved.getSteps().add(\r
- new SlcExecutionStep("Three \n log \n lines"));\r
- return null;\r
- }\r
- });\r
-\r
- dao.update(slcExecRetrieved);\r
-\r
- // updated slcExecution retrieval and comparison\r
- SlcExecution slcExecUpdated = dao.getSlcExecution(slcExec.getUuid());\r
-\r
- assertSlcExecution(slcExecRetrieved, slcExecUpdated);\r
- }\r
-\r
- public void assertSlcExecution(final SlcExecution expected,\r
- final SlcExecution persisted) {\r
- getHibernateTemplate().execute(new HibernateCallback() {\r
-\r
- public Object doInHibernate(Session session)\r
- throws HibernateException, SQLException {\r
- session.refresh(persisted);\r
- SlcExecutionTestUtils.assertSlcExecution(expected, persisted);\r
- return null;\r
- }\r
- });\r
- }\r
-\r
- @Override\r
- protected String getApplicationContextLocation() {\r
- return "org/argeo/slc/hibernate/applicationContext.xml";\r
- }\r
-\r
-}\r