OSCheckerTest.java revision 0a3e979529374fe2ce99e6b1658b77271eab90b2
0N/A/*
0N/A * The contents of this file are subject to the terms of the Common Development and
0N/A * Distribution License (the License). You may not use this file except in compliance with the
0N/A * License.
8N/A *
0N/A * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
0N/A * specific language governing permission and limitations under the License.
0N/A *
0N/A * When distributing Covered Software, include this CDDL Header Notice in each file and include
0N/A * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
0N/A * Header, with the fields enclosed by brackets [] replaced by your own identifying
0N/A * information: "Portions copyright [year] [name of copyright owner]".
0N/A *
0N/A * Copyright 2014 ForgeRock AS.
0N/A */
0N/A
0N/Apackage com.sun.identity.install.tools.util;
0N/A
0N/Aimport org.testng.annotations.Test;
0N/A
0N/Aimport java.util.Arrays;
0N/Aimport java.util.List;
0N/A
0N/Aimport static org.testng.Assert.*;
0N/Aimport static com.sun.identity.install.tools.util.OSChecker.*;
8N/A
8N/Apublic class OSCheckerTest {
8N/A
8N/A private static final String OS_NAME = System.getProperty("os.name");
394N/A private static final List<String> ARCHITECTURES = Arrays.asList(
8N/A "i386", "i686", "x86", "x86_64", "amd64", "PowerPC", "ppc", "ppc64", "sparc");
8N/A
8N/A @Test
8N/A public void testIsUnixOrWindows() {
8N/A assertTrue(isUnix() || isWindows());
8N/A assertFalse(isUnix() && isWindows());
0N/A }
0N/A
0N/A @Test
0N/A public void testLinuxVersionStringParsing() {
0N/A
8N/A String linuxVersionString = "2.6.32-279.14.1.el6.x86_64";
416N/A parseVersion(linuxVersionString);
8N/A assertEquals(getOsMajorVersion(), 2);
8N/A assertEquals(getOsMinorVersion(), 6);
8N/A }
0N/A
0N/A @Test
0N/A public void testOSXVersionStringParsing() {
0N/A String osXVersionString = "10.9.5";
0N/A parseVersion(osXVersionString);
0N/A assertEquals(getOsMajorVersion(), 10);
0N/A assertEquals(getOsMinorVersion(), 9);
0N/A }
0N/A
0N/A @Test
8N/A public void testWindowsVersionStringParsing() {
8N/A String windowsVersionString = "5.1";
8N/A parseVersion(windowsVersionString);
460N/A assertEquals(getOsMajorVersion(), 5);
460N/A assertEquals(getOsMinorVersion(), 1);
460N/A }
8N/A
0N/A @Test
8N/A public void testNoMinorVersionStringParsing() {
8N/A
8N/A String noMinorString = "100";
8N/A parseVersion(noMinorString);
8N/A assertEquals(getOsMajorVersion(), 100);
8N/A assertEquals(getOsMinorVersion(), 0);
8N/A }
0N/A
504N/A @Test
0N/A public void testInvalidVersionStringParsing() {
504N/A
0N/A // The exception output will end up in the TestCase debug log under the
504N/A // target/test-cases directory as set in the POM.
0N/A String exceptionString = "abc.10";
504N/A parseVersion(exceptionString);
504N/A assertEquals(getOsMajorVersion(), 0);
0N/A assertEquals(getOsMinorVersion(), 0);
8N/A }
8N/A
416N/A @Test
8N/A public void testAtLeast() {
427N/A parseVersion("1.2.3");
0N/A assertTrue(atleast(OS_NAME, 1, 0));
0N/A assertTrue(atleast(OS_NAME, 1, 2));
416N/A assertFalse(atleast(OS_NAME, 1, 3));
8N/A assertFalse(atleast(OS_NAME, 2, 1));
8N/A assertFalse(atleast("iOS", 1, 0));
8N/A }
0N/A
8N/A @Test
8N/A public void testArchitecture() {
416N/A int foundArch = 0;
8N/A
8N/A // non-exhaustive list, covers conceivable architectures that might be running unit tests
0N/A for (String arch : ARCHITECTURES) {
8N/A if (matchArch(arch)) {
416N/A foundArch++;
8N/A }
8N/A }
8N/A
8N/A assertEquals(foundArch, 1, "Expected " + System.getProperty("os.arch") + " to be one of " + ARCHITECTURES);
0N/A }
0N/A}
0N/A