Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f8c434a96a250b03aa8b1532995ca56d14411d74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*******************************************************************************
 * Copyright (c) 2013 Red Hat Inc. and others.
 * 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:
 *     Neil Guzman - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.rpm.createrepo.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectCreator;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectNature;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Test case for project creation with CreaterepoProjectCreatorTest class.
 * This checks if the project creator is working, but does not check for
 * initializing of .repo file contents and the content folder. These are done
 * via the wizard (SWTBot test should handle this).
 */
public class CreaterepoProjectCreatorTest {

	private static final String PROJECT_NAME = "createrepo-test-project"; //$NON-NLS-1$
	private static final String REPO_NAME = "createrepo-test-repo.repo"; //$NON-NLS-1$

	private static IWorkspaceRoot root;
	private static NullProgressMonitor monitor;
	private IProject project;

	/**
	 * Initialize workspace root and progress monitor.
	 */
	@BeforeClass
	public static void setUpBeforeClass() {
		root = ResourcesPlugin.getWorkspace().getRoot();
		monitor = new NullProgressMonitor();
	}

	/**
	 * Create the project using CreaterepoProjectCreator.
	 *
	 * @throws CoreException
	 */
	@Before
	public void setUp() throws CoreException{
		if (project == null || !project.exists()) {
			project = CreaterepoProjectCreator.create(PROJECT_NAME, root.getLocation(), REPO_NAME, monitor);
		}
	}

	/**
	 * Forcefully delete the project if it exists.
	 *
	 * @throws CoreException
	 */
	@After
	public void tearDown() throws CoreException {
		if (project != null && project.exists()) {
			project.delete(true, monitor);
		}
	}

	/**
	 * Test to see if the project has been properly created. Content folder
	 * should not appear due to CreaterepoWizard handling its creation. Repo
	 * file should be empty for the same reason.
	 *
	 * @throws CoreException
	 * @throws IOException
	 */
	@Test
	public void testProjectContents() throws CoreException, IOException {
		assertTrue(project.exists());
		// 3 = .project + .repo file
		assertEquals(2, project.members().length);

		// contains the repo file
		assertTrue(project.findMember(REPO_NAME).exists());

		IFile repoFile = (IFile) project.findMember(REPO_NAME);
		// repo file should be empty because test did not go through project creation
		// to initialize .repo contents
		assertEquals(repoFile.getContents().available(), 0);
	}

	/**
	 * Test to see if the project has the proper nature.
	 *
	 * @throws CoreException
	 */
	@Test
	public void testProjectNature() throws CoreException {
		assertTrue(project.hasNature(CreaterepoProjectNature.CREATEREPO_NATURE_ID));
	}

}

Back to the top