blob: 30845780b10e50957a090a79913ad86845586066 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008, 2011 Attensity Europe GmbH and brox IT Solutions GmbH. All rights reserved. This program and the
* accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this
* distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Juergen Schumacher, Andreas Weber, Drazen Cindric, Andreas Schank (all Attensity Europe GmbH) - initial
* implementation
**********************************************************************************************************************/
package org.eclipse.smila.jobmanager.test;
import junit.framework.TestCase;
import org.eclipse.smila.datamodel.AnyMap;
import org.eclipse.smila.jobmanager.InvalidConfigException;
import org.eclipse.smila.jobmanager.JobDefinition;
import org.eclipse.smila.jobmanager.internal.AccessAny;
/**
* Tests for validation in job parsing.
*
*/
public class TestJobDefinition extends TestCase {
/**
* Tests a job with missing "name". Must fail.
*
* @throws Exception
* Exception when converting to or from Any.
*/
public void testMissingName() throws Exception {
final AnyMap jobAny = AccessAny.FACTORY.createAnyMap();
jobAny.put("job-name", "job");
jobAny.put("workflow", "workflow");
try {
new JobDefinition(jobAny);
fail("should not work");
} catch (final Exception ex) {
assertTrue("wrong exception caught: " + ex.toString(), ex instanceof InvalidConfigException);
}
}
/**
* Tests job without mandatory "workflow" name.
*
* @throws Exception
* Exception when converting to or from Any.
*/
public void testMissingWorkflow() throws Exception {
final AnyMap jobAny = AccessAny.FACTORY.createAnyMap();
jobAny.put("name", "job");
final AnyMap parametersAny = AccessAny.FACTORY.createAnyMap();
parametersAny.put("index-name", "index");
jobAny.put("parameters", parametersAny);
try {
new JobDefinition(jobAny);
fail("should not work");
} catch (final Exception ex) {
assertTrue("wrong exception caught: " + ex.toString(), ex instanceof InvalidConfigException);
}
}
/**
* Tests a working job definition. Must not fail.
*
* @throws Exception
* Exception when converting to or from Any.
*/
public void testWorkingDefinition() throws Exception {
final AnyMap jobAny = AccessAny.FACTORY.createAnyMap();
jobAny.put("name", "job");
final AnyMap parametersAny = AccessAny.FACTORY.createAnyMap();
parametersAny.put("index-name", "index");
jobAny.put("parameters", parametersAny);
jobAny.put("workflow", "workflow");
jobAny.put("additionalData", "additional data");
final JobDefinition jdef = new JobDefinition(jobAny);
assertEquals("name does not match", jobAny.getStringValue("name"), jdef.getName());
assertEquals("workflow does not match", jobAny.getStringValue("workflow"), jdef.getWorkflow());
assertEquals("parameters do not match", jobAny.getMap("parameters").getStringValue("index-name"), jdef
.getParameters().get("index-name").getExpression());
}
/**
* Tests the conversion to and from Any.
*
* @throws Exception
* Exception when converting to or from Any.
*/
public void testWorkingDefinitionToAndFromAny() throws Exception {
final AnyMap jobAny = AccessAny.FACTORY.createAnyMap();
jobAny.put("name", "job");
final AnyMap parametersAny = AccessAny.FACTORY.createAnyMap();
parametersAny.put("index-name", "index");
jobAny.put("parameters", parametersAny);
jobAny.put("workflow", "workflow");
jobAny.put("additionalData", "additional data");
final JobDefinition jdef = new JobDefinition(jobAny);
final AnyMap reEngineeredAny = jdef.toAny();
// damn: Any does not provide a usable equals() method :-(
assertEquals("input and output any name do not match", jobAny.getStringValue("name"),
reEngineeredAny.getStringValue("name"));
assertEquals("input and output any workflow do not match", jobAny.getStringValue("workflow"),
reEngineeredAny.getStringValue("workflow"));
assertEquals("input and output any parameters do not match",
jobAny.getMap("parameters").getStringValue("index-name"), reEngineeredAny.getMap("parameters")
.getStringValue("index-name"));
assertEquals("input and output additional attributes do not match", jobAny.getStringValue("additionalData"),
reEngineeredAny.getStringValue("additionalData"));
}
}