X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.hibernate%2Fsrc%2Ftest%2Fjava%2Forg%2Fargeo%2Fslc%2Fhibernate%2Fprocess%2FSlcExecutionHibernateTest.java;fp=runtime%2Forg.argeo.slc.support.hibernate%2Fsrc%2Ftest%2Fjava%2Forg%2Fargeo%2Fslc%2Fhibernate%2Fprocess%2FSlcExecutionHibernateTest.java;h=0000000000000000000000000000000000000000;hb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;hp=b4798ce602567c4066ffb5d2359be621fda2e8b8;hpb=a5b25ca3e5efc8de3571993f6bfc1671c0e2f3ba;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.hibernate/src/test/java/org/argeo/slc/hibernate/process/SlcExecutionHibernateTest.java b/runtime/org.argeo.slc.support.hibernate/src/test/java/org/argeo/slc/hibernate/process/SlcExecutionHibernateTest.java deleted file mode 100644 index b4798ce60..000000000 --- a/runtime/org.argeo.slc.support.hibernate/src/test/java/org/argeo/slc/hibernate/process/SlcExecutionHibernateTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * 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. - */ -package org.argeo.slc.hibernate.process; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.argeo.slc.dao.process.SlcExecutionDao; -import org.argeo.slc.hibernate.unit.HibernateTestCase; -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionStep; -import org.argeo.slc.unit.process.SlcExecutionTestUtils; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.springframework.orm.hibernate3.HibernateCallback; - -public class SlcExecutionHibernateTest extends HibernateTestCase { - - public void testSave() { - SlcExecutionDao dao = getBean(SlcExecutionDao.class); - - SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution(); - slcExec.getSteps().add(new SlcExecutionStep("A log line")); - slcExec.getSteps().add(new SlcExecutionStep("Two log\nlines")); - - dao.create(slcExec); - - SlcExecution slcExecPersisted = dao.getSlcExecution(slcExec.getUuid()); - assertSlcExecution(slcExec, slcExecPersisted); - } - - public void testTailSteps() { - SlcExecutionDao dao = getBean(SlcExecutionDao.class); - - SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution(); - int totalStepCount = 20; - for (int i = 0; i < totalStepCount; i++) { - slcExec.getSteps().add(new SlcExecutionStep("Log " + i)); - } - dao.create(slcExec); - - int lastStepsCount = 7; - List firstSteps = dao.tailSteps(slcExec.getUuid(), - lastStepsCount); - assertEquals(lastStepsCount, firstSteps.size()); - - SlcExecutionStep lastStep = firstSteps.get(lastStepsCount - 1); - - List additionalSteps = new ArrayList(); - int additionalStepsCount = 13; - for (int i = 0; i < additionalStepsCount; i++) { - additionalSteps.add(new SlcExecutionStep("Additonal log " + i)); - } - dao.addSteps(slcExec.getUuid(), additionalSteps); - - List lastSteps = dao.tailSteps(slcExec.getUuid(), - lastStep.getUuid()); - assertEquals(additionalStepsCount, lastSteps.size()); - } - - public void testModify() { - SlcExecutionDao dao = getBean(SlcExecutionDao.class); - - // slcExecution Creation - SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution(); - slcExec.getSteps().add(new SlcExecutionStep("A log line")); - slcExec.getSteps().add(new SlcExecutionStep("Two log\nlines")); - - dao.create(slcExec); - - // slcExecution retrieval and update - final SlcExecution slcExecRetrieved = dao.getSlcExecution(slcExec - .getUuid()); - - getHibernateTemplate().execute(new HibernateCallback() { - - public Object doInHibernate(Session session) - throws HibernateException, SQLException { - session.refresh(slcExecRetrieved); - List logLineListStep0 = slcExecRetrieved.getSteps() - .get(0).getLogLines(); - for (String logLine : logLineListStep0) - logLine = logLine + "appended Log text"; - - slcExecRetrieved.getSteps().get(0) - .setLogLines(logLineListStep0); - slcExecRetrieved.getSteps().add( - new SlcExecutionStep("Three \n log \n lines")); - return null; - } - }); - - dao.update(slcExecRetrieved); - - // updated slcExecution retrieval and comparison - SlcExecution slcExecUpdated = dao.getSlcExecution(slcExec.getUuid()); - - assertSlcExecution(slcExecRetrieved, slcExecUpdated); - } - - public void assertSlcExecution(final SlcExecution expected, - final SlcExecution persisted) { - getHibernateTemplate().execute(new HibernateCallback() { - - public Object doInHibernate(Session session) - throws HibernateException, SQLException { - session.refresh(persisted); - SlcExecutionTestUtils.assertSlcExecution(expected, persisted); - return null; - } - }); - } - - @Override - protected String getApplicationContextLocation() { - return "org/argeo/slc/hibernate/applicationContext.xml"; - } - -}