Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4d513c64bdae09c5ec2764b73bf388f5fd085353 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*******************************************************************************
 * Copyright (c) 2001, 2012 Oracle Corporation and others.
 * All rights reserved. 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:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/


package org.eclipse.jst.jsf.core.tests.facet;

import junit.framework.TestCase;

import org.eclipse.core.runtime.IStatus;


/**
 * @author Debajit Adhikary
 *
 */
public abstract class LibraryValidatorTest extends TestCase
{
    private String classNameIdentifyingJarToUse;
    /*
    private String jarPath;
    private String jarPathWithoutImplementationVersionEntry;
    private String jarPathWithNonstandardImplementationVersionEntry;
    private String expectedLibraryVersion;
    */
    private UserLibraryVersionValidatorProxy validator;


    /**
     * @param name
     */
    public LibraryValidatorTest (final String name)
    {
        super(name);
    }


    public LibraryValidatorTest (final String name,
                                 final String classNameIdentifyingJarToUse
                                 /*
                                 final String jarPath,
                                 final String jarPathWithoutImplementationVersionEntry,
                                 final String jarPathWithNonstandardImplementationVersionEntry,
                                 final String expectedLibraryVersion*/
                                 )
    {
        super(name);

        this.classNameIdentifyingJarToUse = classNameIdentifyingJarToUse;
        /*
        this.jarPath = jarPath;
        this.jarPathWithoutImplementationVersionEntry = jarPathWithoutImplementationVersionEntry;
        this.jarPathWithNonstandardImplementationVersionEntry = jarPathWithNonstandardImplementationVersionEntry;
        this.expectedLibraryVersion = expectedLibraryVersion;
        */

        this.validator = new UserLibraryVersionValidatorProxy(this.classNameIdentifyingJarToUse);
    }


    public void testVersionStringSuffixMatch ()
    {
        assertNotNull(validator);

        final IStatus status = validator.validateVersionStrings("1.2", "1.1.2");
        assertEquals(IStatus.WARNING, status.getSeverity());
    }


    public void testVersionStringPrefixMatch ()
    {
        assertNotNull(validator);

        final IStatus status = validator.validateVersionStrings("1.2", "1.2.11");
        assertEquals(IStatus.OK, status.getSeverity());
    }


    public void testNullLibraryVersionString ()
    {
        assertNotNull(validator);

        final IStatus status = validator.validateVersionStrings("1.2", null);
        assertEquals(IStatus.WARNING, status.getSeverity());
    }


    public void testNullFacetVersionString ()
    {
        assertNotNull(validator);

        try
        {
            validator.validateVersionStrings(null, "1.0.1.2.11"); // Fails
        }
        catch (final IllegalArgumentException e)
        {
            assertEquals("Cannot read facet version", e.getLocalizedMessage());
            return;
        }

        fail();
    }

    /*
    protected File getFileFromPlugin (final String relativePathToFile,
                                      final Plugin plugin)
    throws IOException, URISyntaxException
    {
        final Bundle bundle = TestsPlugin.getDefault().getBundle();

        final URL bundleUrl = bundle.getEntry(relativePathToFile);
        assertNotNull(bundleUrl);

        final URL fileUrl = FileLocator.toFileURL(bundleUrl);
        final File file = new File(fileUrl.getPath());
        assertTrue(file.exists());
        return file;
    }
    */

    /*
    public void testReadLibraryVersionFromJarWithManifestEntry ()
    throws IOException, URISyntaxException
    {
        final JarFile jarFile = new JarFile(getFileFromPlugin(jarPath, TestsPlugin.getDefault()));
        assertEquals(expectedLibraryVersion, validator.getLibraryVersion(jarFile)); 
    }
	*/

    /*
    public void testReadLibraryVersionFromJarWithoutManifestEntry ()
    throws IOException, URISyntaxException
    {
        final JarFile jarFile = new JarFile(getFileFromPlugin(jarPathWithoutImplementationVersionEntry, TestsPlugin.getDefault()));
        assertNull("Was expecting library-version string to be null", validator.getLibraryVersion(jarFile)); //$NON-NLS-1$
    }
    */

    /**
     * Regression test-case. This would fail earlier without the patch in
     *
     * "JSF Facet version validator fails to validate some non-standard jars"
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=286351 
     *
     * @throws IOException
     * @throws URISyntaxException
     *
     */
    /*
    public void testReadLibraryVersionFromJarWithNonstandardImplementationVersion()
    throws IOException, URISyntaxException
    {
        final JarFile jarFile = new JarFile(getFileFromPlugin(jarPathWithNonstandardImplementationVersionEntry, TestsPlugin.getDefault()));
        assertNotNull("Was expecting library-version string to be non-null", validator.getLibraryVersion(jarFile)); //$NON-NLS-1$
        assertEquals(expectedLibraryVersion, validator.getLibraryVersion(jarFile));
    }
    */
}

Back to the top