All Downloads are FREE. Search and download functionalities are using the official Maven repository.

protoj.lang.internal.acme.AssertVerifyTar Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2009 Ashley Williams
 * 
 * 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 protoj.lang.internal.acme;

import org.junit.Assert;

import protoj.lang.ProjectLayout;
import protoj.lang.ScriptSession;
import protoj.util.ArgRunnable;
import protoj.util.CommandTask;

/**
 * These assertions trigger when the verify-tar command is specified. After the
 * first call there should be no tar file to verify so we check for the correct
 * error. After the second call there should be tar file with no src directory
 * so we check for the correct error. After the third call there should be a
 * correct tar file so we should be able to verify correct operation of the
 * verification process.
 * 
 * @author Ashley Williams
 * 
 */
final class AssertVerifyTar implements ArgRunnable {
	public static final String NO_TAR = "no tar";

	public static final String NO_SRC = "no src";

	public static final String OK = "ok";

	private final AcmeSession acmeSession;

	private int testIndex = 0;

	public AssertVerifyTar(AcmeSession acmeSession) {
		this.acmeSession = acmeSession;
	}

	public void run(ScriptSession projectSession) {
		ProjectLayout acmeLayout = acmeSession.getProject().getLayout();
		String log = acmeSession.getProject().getLayout().loadLog();
		String tag = projectSession.getCurrentTag();

		if (tag.equals(NO_TAR)) {
			// no tar file
			Assert.assertTrue(log, log.contains("unable to find tar file"));
		} else if (tag.equals(NO_SRC)) {
			// no src file
			Assert
					.assertTrue(log, log
							.contains("unable to find src directory"));
		} else if (tag.equals(OK)) {
			// tar verified successfully
			CommandTask exec = projectSession.getCurrentExec();
			Assert.assertTrue(exec.getStdout(), exec.isSuccess());
		}

		acmeLayout.getLogFile().delete();
		testIndex++;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy