Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3393f8564851fcf9c6c4d34be4572cb9010d3883 (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
152
/*******************************************************************************
 * Copyright (c) 2010, 2011 IBM Corporation and others
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.metatype.tests;

import org.junit.*;
import org.osgi.framework.Bundle;
import org.osgi.service.metatype.*;

public class AttributeTypePasswordTest extends AbstractTest {
	private Bundle bundle;

	@Before
	public void setUp() throws Exception {
		super.setUp();
		bundle = bundleInstaller.installBundle("tb1"); //$NON-NLS-1$
		bundle.start();
	}

	/*
	 * Ensures the PASSWORD type is recognized.
	 */
	@Test
	public void testAttributeTypePassword1() {
		doTestAttributeTypePassword1();
		restartMetatype();
		doTestAttributeTypePassword1();
	}

	private void doTestAttributeTypePassword1() {
		MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
		ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$
		AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
		for (int i = 0; i < ads.length; i++) {
			if (ads[i].getID().equals("password1")) { //$NON-NLS-1$
				Assert.assertEquals("Attribute type is not PASSWORD", AttributeDefinition.PASSWORD, ads[i].getType()); //$NON-NLS-1$
			}
		}
	}

	/*
	 * Ensures the PASSWORD type is treated the same as the STRING type.
	 */
	@Test
	public void testAttributeTypePassword2() {
		doTestAttributeTypePassword2();
		restartMetatype();
		doTestAttributeTypePassword2();
	}

	private void doTestAttributeTypePassword2() {
		MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
		ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$
		AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
		AttributeDefinition ad = findAttributeDefinitionById("password1", ads); //$NON-NLS-1$
		Assert.assertNotNull("Attribute definition not found", ad); //$NON-NLS-1$
		assertValidationPass("1234abcd", ad); //$NON-NLS-1$
	}

	/*
	 * Ensures the PASSWORD type is treated the same as the STRING type.
	 */
	@Test
	public void testAttributeTypePassword3() {
		doTestAttributeTypePassword3();
		restartMetatype();
		doTestAttributeTypePassword3();
	}

	private void doTestAttributeTypePassword3() {
		MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
		ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$
		AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
		AttributeDefinition ad = findAttributeDefinitionById("password2", ads); //$NON-NLS-1$
		assertValidationPass("password", ad); //$NON-NLS-1$
		assertValidationFail("1234abcd", ad); //$NON-NLS-1$
	}

	/*
	 * Ensures the PASSWORD type is treated the same as the STRING type.
	 * PASSWORD length should be no less than min.
	 */
	@Test
	public void testAttributeTypePassword4() {
		doTestAttributeTypePassword4();
		restartMetatype();
		doTestAttributeTypePassword4();
	}

	private void doTestAttributeTypePassword4() {
		MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
		ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$
		AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
		AttributeDefinition ad = findAttributeDefinitionById("password3", ads); //$NON-NLS-1$
		assertValidationPass("12345678", ad); //$NON-NLS-1$
		assertValidationPass("123456789", ad); //$NON-NLS-1$
		assertValidationFail("1234567", ad); //$NON-NLS-1$
	}

	/*
	 * Ensures the PASSWORD type is treated the same as the STRING type.
	 * PASSWORD length should be no greater than max.
	 */
	@Test
	public void testAttributeTypePassword5() {
		doTestAttributeTypePassword5();
		restartMetatype();
		doTestAttributeTypePassword5();
	}

	private void doTestAttributeTypePassword5() {
		MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
		ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$
		AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
		AttributeDefinition ad = findAttributeDefinitionById("password4", ads); //$NON-NLS-1$
		assertValidationPass("12345", ad); //$NON-NLS-1$
		assertValidationPass("1234", ad); //$NON-NLS-1$
		assertValidationFail("123456", ad); //$NON-NLS-1$
	}

	/*
	 * Ensures the PASSWORD type is treated the same as the STRING type.
	 * PASSWORD length should be no less than min and no greater than max.
	 */
	@Test
	public void testAttributeTypePassword6() {
		doTestAttributeTypePassword6();
		restartMetatype();
		doTestAttributeTypePassword6();
	}

	private void doTestAttributeTypePassword6() {
		MetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
		ObjectClassDefinition ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.tb1", null); //$NON-NLS-1$
		AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
		AttributeDefinition ad = findAttributeDefinitionById("password5", ads); //$NON-NLS-1$
		assertValidationPass("123", ad); //$NON-NLS-1$
		assertValidationFail("12", ad); //$NON-NLS-1$
		assertValidationPass("123456", ad); //$NON-NLS-1$
		assertValidationFail("1234567", ad); //$NON-NLS-1$
	}
}

Back to the top