Skip to main content
summaryrefslogtreecommitdiffstats
blob: eba1bbf4cf70a6dbc9b828fc9c7e4877318d0e2a (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*******************************************************************************
 * Copyright (c) 2005 Oracle Corporation.
 * 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:
 *    Oracle - initial API and implementation
 *******************************************************************************/ 
package org.eclipse.jst.jsf.core.tests.project.facet;

import java.util.Set;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.eclipse.core.resources.IProject;
import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil;
import org.eclipse.jst.jsf.core.internal.project.facet.IJSFFacetInstallDataModelProperties;
import org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider;
import org.eclipse.jst.jsf.core.tests.util.JSFCoreUtilHelper;
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;

@SuppressWarnings("deprecation")
public class JSFFacetInstallDataModelProviderTestCases extends TestCase {
	private static final String PROJ_2_3_NAME = "_TEST_2_3_PROJECT";
	//private static final String PROJ_2_4_NAME = "_TEST_2_4_PROJECT";
	
	private JSFFacetInstallDataModelProvider dm;
	
	protected void setUp() throws Exception {		
		//seed JSFLib registry if not present
		JSFCoreUtilHelper.createJSFLibraryRegistry();
		//create a project, if one doesn't exist in the current workspace
		IProject project = JSFCoreUtilHelper.createWebProject(PROJ_2_3_NAME);
		//create lib
		JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getDefaultImplementation();
		
		dm = new JSFFacetInstallDataModelProvider();
		IDataModel model = DataModelFactory.createDataModel(dm);	
		model.setStringProperty(IJSFFacetInstallDataModelProperties.FACET_PROJECT_NAME, project.getName());
	}

	/*
	 * Test method for 'org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider.getPropertyNames()'
	 */
	public void testGetPropertyNames() {	
		Set<?> names = dm.getPropertyNames();
		Assert.assertNotNull(names);
//		Assert.assertTrue(names.contains(IJSFFacetInstallDataModelProperties.IMPLEMENTATION));
//		Assert.assertTrue(names.contains(IJSFFacetInstallDataModelProperties.DEPLOY_IMPLEMENTATION));
		Assert.assertTrue(names.contains(IJSFFacetInstallDataModelProperties.CONFIG_PATH));
		Assert.assertTrue(names.contains(IJSFFacetInstallDataModelProperties.SERVLET_NAME));
		Assert.assertTrue(names.contains(IJSFFacetInstallDataModelProperties.SERVLET_URL_PATTERNS));
		Assert.assertTrue(names.contains(IJSFFacetInstallDataModelProperties.WEBCONTENT_DIR));
		
		Assert.assertTrue(names.contains(IJSFFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE));
	}

	/*
	 * Test method for 'org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider.getDefaultProperty(String)'
	 */
	public void testGetDefaultPropertyString() {
//		Assert.assertNotNull(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION));
//		Assert.assertTrue(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION) instanceof JSFLibraryInternalReference);
//		JSFLibraryInternalReference ref = (JSFLibraryInternalReference)dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION) ;
//		Assert.assertTrue(ref.getLibrary() == jsfLib);
//		Assert.assertTrue(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.DEPLOY_IMPLEMENTATION) == Boolean.TRUE);
		Assert.assertTrue(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH) != null);
		Assert.assertTrue(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.SERVLET_NAME) != null);
		Assert.assertTrue(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.SERVLET_URL_PATTERNS) != null);
		Assert.assertTrue(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.WEBCONTENT_DIR) != null);
		
//		Assert.assertTrue(dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE) != null);
	}

	/*
	 * Test method for 'org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider.validate(String)'

	public void testValidateString() {
		//positive tests		
		IDataModel model = dm.getDataModel();
		
		model.setStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH, (String)dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH));
		model.setProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION, jsfLib);
		model.setStringProperty(IJSFFacetInstallDataModelProperties.SERVLET_NAME, (String)dm.getDefaultProperty(IJSFFacetInstallDataModelProperties.SERVLET_NAME));
		
		Assert.assertTrue(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());
		Assert.assertTrue(dm.validate(IJSFFacetInstallDataModelProperties.IMPLEMENTATION).isOK());
		Assert.assertTrue(dm.validate(IJSFFacetInstallDataModelProperties.SERVLET_NAME).isOK());
		
		model.setStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH, "foo.xml");
		Assert.assertTrue(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());
		//negative tests
		//config path
		model.setStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH, "");
		Assert.assertFalse(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());

		model.setStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH, "../../../foo.xml");
		Assert.assertFalse(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());
		
		model.setStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH, "WEB-INF/xxx.txt");
		Assert.assertFalse(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());
		
		String pathWithDevice = new Path(Platform.getLocation().getDevice(), "/temp/faces-config.xml").toOSString();
		model.setStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH, pathWithDevice );
		Assert.assertFalse(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());

		model.setStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH, "\\WEB-INF\\xxx.txt");
		Assert.assertFalse(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());

		//impl
		model.setProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION, null);				
		Assert.assertFalse(dm.validate(IJSFFacetInstallDataModelProperties.CONFIG_PATH).isOK());
		
		//servlet name		
		//can't check null name because null set returns default value
		model.setStringProperty(IJSFFacetInstallDataModelProperties.SERVLET_NAME, "   ");
		Assert.assertFalse(dm.validate(IJSFFacetInstallDataModelProperties.SERVLET_NAME).isOK());

	}
	 */


    /*
     * Test method for: 
     *     org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider.isValidConfigFileName()
     *     org.eclipse.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider.validateConfigLocation()
     */
    public void testConfigFileNameValidation ()
    {
        assertTrue(JSFFacetInstallDataModelProvider.isValidConfigFileName("faces-config.xml"));
        assertTrue(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml"));
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces config.xml")); // Invalid
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config//faces-config.xml")); // Invalid
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config///faces-config.xml")); // Invalid 
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml,/WEB-INF/config/faces-config2.xml")); // Invalid 
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml, /WEB-INF/config/faces-config2.xml")); // Invalid 
        
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml, ")); // Invalid 
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml. ")); // Invalid 

        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml%")); // Invalid 
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml.&65")); // Invalid 
        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/faces-config.xml*")); // Invalid 

        assertFalse(JSFFacetInstallDataModelProvider.isValidConfigFileName("/WEB-INF/config/face*s-config.xml*")); // Invalid 
    }
}

Back to the top