/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2018 JaamSim Software Inc.
 *
 * 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 com.jaamsim.basicsim;

import java.net.URL;
import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

import com.jaamsim.input.Input;
import com.jaamsim.input.InputAgent;
import com.jaamsim.input.KeywordIndex;

public class TestSimulation {

	@Before
	public void setupTests() {
		if (Simulation.getInstance() != null)
			Simulation.clear();
		InputAgent.setBatch(true);

		// Load the autoload file
		InputAgent.setRecordEdits(false);
		InputAgent.readResource("<res>/inputs/autoload.cfg");
	}

	@Test
	public void testAllDefineableTypes() {
		// Define an instance of every drag-and-drop type
		for (ObjectType each: Entity.getClonesOfIterator(ObjectType.class)) {
			Class<? extends Entity> proto = Input.parseEntityType(each.getName());
			Entity ent = InputAgent.defineEntityWithUniqueName(proto, each.getName(), "-", true);
		}
	}

	@Test
	public void testAllEditableInputs() {
		// Define an instance of every drag-and-drop type
		for (ObjectType each: Entity.getClonesOfIterator(ObjectType.class)) {
			Class<? extends Entity> proto = Input.parseEntityType(each.getName());
			Entity ent = InputAgent.defineEntityWithUniqueName(proto, each.getName(), "-", true);

			KeywordIndex kw = new KeywordIndex("none", new ArrayList<String>(0), null);
			for (Input<?> inp : ent.getEditableInputs()) {
				// This is a hack to make the in non-default so we hit updateForInput()
				inp.setTokens(kw);
				InputAgent.apply(ent, inp, kw);
			}
		}
	}

	@Test
	public void testSimpleInputFile() {
		URL url = TestSimulation.class.getResource("Test0001.cfg");
		InputAgent.readResource(url.toString());
	}
}

@@ -716,24 +716,49 @@
 ArrayList;%0A%0A
+import org.junit.Assert;%0A
 import org.j
@@ -770,16 +770,16 @@
 Before;%0A
-
 import o
@@ -901,16 +901,55 @@
 rdIndex;
+%0Aimport com.jaamsim.input.OutputHandle;
 %0A%0Apublic
@@ -1611,24 +1611,45 @@
 eInputs() %7B%0A
+%09%09int numErrors = 0;%0A
 %09%09// Define 
@@ -2193,19 +2193,333 @@
 );%0A%09%09%09%7D%0A
-%09%09%7D
+%0A%09%09%09for (OutputHandle out : OutputHandle.getOutputHandleList(ent)) %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09InputAgent.getValueAsString(out, 0.0d, %22%25s%22, 1.0d);%0A%09%09%09%09%7D%0A%09%09%09%09catch (Throwable t) %7B%0A%09%09%09%09%09System.out.println(%22Ent: %22 + ent.getName() + %22 Out: %22 + out.getName());%0A%09%09%09%09%09numErrors++;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09if (numErrors %3E 0)%0A%09%09%09Assert.fail();
 %0A%09%7D%0A%0A%09@T

add a call to get a value from every defined output