1 /*
   2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.oracle.tools.packager.windows;
  27 
  28 import com.oracle.tools.packager.AbstractImageBundler;
  29 import junit.framework.Assert;
  30 import org.junit.Test;
  31 import org.junit.runner.RunWith;
  32 import org.junit.runners.Parameterized;
  33 
  34 import java.util.Arrays;
  35 import java.util.Collection;
  36 import java.util.HashMap;
  37 import java.util.Map;
  38 
  39 @RunWith(value = Parameterized.class)
  40 public class RuntimeFlagsParserTest {
  41 
  42     @Parameterized.Parameters
  43     public static Collection<String[]> data() {
  44         return Arrays.asList(new String[][] {
  45                 {
  46                     "java version \"1.7.0_51\"\nJava(TM) SE Runtime Environment (build 1.7.0_51-b13)\nJava HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)\n",
  47                     "64", "1.7.0_51", "1.7.0", "51", null, "7", "51", "51", "0"
  48                 },
  49                 {
  50                     "java version \"1.8.0_05-ea\"\nJava(TM) SE Runtime Environment (build 1.8.0_05-ea-b03)\nJava HotSpot(TM) Client VM (build 25.5-b01, mixed mode)\n",
  51                     "32", "1.8.0_05", "1.8.0", "05", "ea", "8", "05", "05", "0"
  52                 },
  53                 {
  54                     "java version \"1.8.0_40\"\nJava(TM) SE Runtime Environment (build 1.8.0_40-b25)\nJava HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)",
  55                     "64", "1.8.0_40", "1.8.0", "40", null, "8", "40", "40", "0"
  56                 },
  57                 {
  58                     "java version \"9.1.2.3-ea\"\nJava(TM) SE Runtime Environment (build 9.1.2.3-ea-4+2015-03-14-092653.pi.jdk9)\nJava HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)",
  59                     "64", "9.1.2.3", "9.1.2.3", "1", "ea", "9", "1", "2", "3"
  60                 }
  61         });
  62     }
  63 
  64     String versionText;
  65     String bitArch;
  66     String fullVersion;
  67     String releaseVersion;
  68     String updateVersion;
  69     String versionModifiers;
  70     String versionMajor;
  71     String versionMinor;
  72     String versionSecurity;
  73     String versionPatch;
  74 
  75     public RuntimeFlagsParserTest(String versionText, String bitArch, String fullVersion, String releaseVersion, String updateVersion, String versionModifiers, String versionMajor, String versionMinor, String versionSecurity, String versionPatch) {
  76         this.versionText = versionText;
  77         this.bitArch = bitArch;
  78         this.fullVersion = fullVersion;
  79         this.releaseVersion = releaseVersion;
  80         this.updateVersion = updateVersion;
  81         this.versionModifiers = versionModifiers;
  82         this.versionMajor = versionMajor;
  83         this.versionMinor = versionMinor;
  84         this.versionSecurity = versionSecurity;
  85         this.versionPatch = versionPatch;
  86     }
  87 
  88     @Test
  89     public void validateVersionText() {
  90         Map<String, Object> params = new HashMap<>();
  91         AbstractImageBundler.extractFlagsFromVersion(params, versionText);
  92 
  93         Assert.assertEquals(bitArch, params.get(".runtime.bit-arch"));
  94         Assert.assertEquals(fullVersion, params.get(".runtime.version"));
  95         Assert.assertEquals(releaseVersion, params.get(".runtime.version.release"));
  96         Assert.assertEquals(updateVersion, params.get(".runtime.version.update"));
  97         Assert.assertEquals(versionModifiers, params.get(".runtime.version.modifiers"));
  98         Assert.assertEquals(versionMajor, params.get(".runtime.version.major"));
  99         Assert.assertEquals(versionMinor, params.get(".runtime.version.minor"));
 100         Assert.assertEquals(versionSecurity, params.get(".runtime.version.security"));
 101         Assert.assertEquals(versionPatch, params.get(".runtime.version.patch"));
 102     }
 103 }