001/* 002 * Units of Measurement TCK 003 * Copyright © 2005-2017, Jean-Marie Dautelle, Werner Keil, V2COM. 004 * 005 * All rights reserved. 006 * 007 * Redistribution and use in source and binary forms, with or without modification, 008 * are permitted provided that the following conditions are met: 009 * 010 * 1. Redistributions of source code must retain the above copyright notice, 011 * this list of conditions and the following disclaimer. 012 * 013 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions 014 * and the following disclaimer in the documentation and/or other materials provided with the distribution. 015 * 016 * 3. Neither the name of JSR-385 nor the names of its contributors may be used to endorse or promote products 017 * derived from this software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 021 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package tech.units.tck.tests.spi; 031 032import static org.testng.AssertJUnit.assertNotNull; 033import static tech.units.tck.TCKRunner.SPEC_ID; 034import static tech.units.tck.TCKRunner.SPEC_VERSION; 035 036import java.util.Set; 037 038import static org.testng.Assert.assertEquals; 039import static org.testng.AssertJUnit.assertFalse; 040 041import javax.measure.BinaryPrefix; 042import javax.measure.MetricPrefix; 043import javax.measure.Prefix; 044import javax.measure.spi.FormatService; 045import javax.measure.spi.ServiceProvider; 046import javax.measure.spi.SystemOfUnitsService; 047import javax.measure.spi.UnitFormatService; 048 049import org.jboss.test.audit.annotations.SpecAssertion; 050import org.jboss.test.audit.annotations.SpecVersion; 051import org.testng.annotations.Test; 052 053/** 054 * Test class for Services. 055 * 056 * @author Werner Keil 057 * @version 1.0, August 16, 2016 058 * @since 1.0 059 */ 060@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION) 061public class ServicesTest { 062 private static final String SECTION = "5.4"; 063 private static final String DESCRIPTION = SECTION + " Services"; 064 065 // ************************ 5.4 Services 066 // ************************ 067 /** 068 * Access available UnitFormatServices. 069 */ 070 @Test(groups = { "spi" }, description = DESCRIPTION) 071 @SpecAssertion(section = SECTION, id = "54-A1") 072 public void testFormatService() { 073 for (ServiceProvider provider : ServiceProvider.available()) { 074 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 075 UnitFormatService service = provider.getFormatService(); 076 assertNotNull("Section " + SECTION + ": FormatService is null", service); 077 } 078 } 079 080 // ************************ 5.4 Services 081 // ************************ 082 /** 083 * Access default UnitFormats in UnitFormatServices. 084 */ 085 @Test(groups = { "spi" }, description = DESCRIPTION) 086 @SpecAssertion(section = SECTION, id = "54-A2") 087 public void testFormatServiceDefaultFormat() { 088 for (ServiceProvider provider : ServiceProvider.available()) { 089 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 090 FormatService service = provider.getFormatService(); 091 assertNotNull("Section " + SECTION + ": UnitFormatService is null", service); 092 assertNotNull("Section " + SECTION + ": Default UnitFormat is null", service.getUnitFormat()); 093 assertNotNull("Section " + SECTION + ": Available UnitFormat names are null", 094 service.getAvailableFormatNames()); 095 assertFalse("Section " + SECTION + " No available UnitFormat names found", 096 service.getAvailableFormatNames().isEmpty()); 097 } 098 } 099 100 // ************************ 5.4 Services 101 // ************************ 102 /** 103 * Access available UnitFormats in UnitFormatServices. 104 */ 105 @Test(groups = { "spi" }, description = DESCRIPTION) 106 @SpecAssertion(section = SECTION, id = "54-A3") 107 public void testFormatServiceAvailableFormats() { 108 for (ServiceProvider provider : ServiceProvider.available()) { 109 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 110 FormatService service = provider.getFormatService(); 111 assertNotNull("Section " + SECTION + ": FormatService is null", service); 112 assertNotNull("Section " + SECTION + ": Available UnitFormat names are null", 113 service.getAvailableFormatNames()); 114 assertFalse("Section " + SECTION + " No available UnitFormat names found", 115 service.getAvailableFormatNames().isEmpty()); 116 } 117 } 118 119 // ************************ 5.4 Services 120 // ************************ 121 /** 122 * Access available SystemOfUnitsServices. 123 */ 124 @Test(groups = { "spi" }, description = DESCRIPTION) 125 @SpecAssertion(section = SECTION, id = "54-A4") 126 public void testSystemOfUnitsService() { 127 for (ServiceProvider provider : ServiceProvider.available()) { 128 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 129 SystemOfUnitsService service = provider.getSystemOfUnitsService(); 130 assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); 131 } 132 } 133 134 // ************************ 5.4 Services 135 // ************************ 136 /** 137 * Access default SystemOfUnits in SystemOfUnitsService. 138 */ 139 @Test(groups = { "spi" }, description = DESCRIPTION) 140 @SpecAssertion(section = SECTION, id = "54-A5") 141 public void testSystemOfUnitsServiceDefaultSystem() { 142 for (ServiceProvider provider : ServiceProvider.available()) { 143 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 144 SystemOfUnitsService service = provider.getSystemOfUnitsService(); 145 assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); 146 assertNotNull("Section " + SECTION + ": Default SystemOfUnits is null", service.getSystemOfUnits()); 147 } 148 } 149 150 // ************************ 5.4 Services 151 // ************************ 152 /** 153 * Access available Systems OfUnits in SystemOfUnitsService. 154 */ 155 @Test(groups = { "spi" }, description = DESCRIPTION) 156 @SpecAssertion(section = SECTION, id = "54-A6") 157 public void testSystemOfUnitsServiceAvailableSystems() { 158 for (ServiceProvider provider : ServiceProvider.available()) { 159 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 160 SystemOfUnitsService service = provider.getSystemOfUnitsService(); 161 assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); 162 assertNotNull("Section " + SECTION + ": Available SystemOfUnits are null", 163 service.getAvailableSystemsOfUnits()); 164 assertFalse("Section " + SECTION + " No available SystemOfUnits found", 165 service.getAvailableSystemsOfUnits().isEmpty()); 166 } 167 } 168 169 /** 170 * Access Binary Prefixes in SystemOfUnitsService. 171 */ 172 @Test(groups = { "spi" }, description = DESCRIPTION) 173 @SpecAssertion(section = SECTION, id = "54-A7") 174 public void testSystemOfUnitsServicePrefixBinary() { 175 for (ServiceProvider provider : ServiceProvider.available()) { 176 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 177 final SystemOfUnitsService service = provider.getSystemOfUnitsService(); 178 assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); 179 Set<Prefix> prefixes = service.getPrefixes(BinaryPrefix.class); 180 assertNotNull("Section " + SECTION + ": Binary Prefixes are null", prefixes); 181 assertFalse("Section " + SECTION + " No Binary Prefixes found", prefixes.isEmpty()); 182 assertEquals(8, prefixes.size(), "Section " + SECTION + " Wrong Number of Binary Prefixes"); 183 } 184 } 185 186 /** 187 * Access Metric Prefixes in SystemOfUnitsService. 188 */ 189 @Test(groups = { "spi" }, description = DESCRIPTION) 190 @SpecAssertion(section = SECTION, id = "54-A8") 191 public void testSystemOfUnitsServicePrefixMetric() { 192 for (ServiceProvider provider : ServiceProvider.available()) { 193 assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); 194 final SystemOfUnitsService service = provider.getSystemOfUnitsService(); 195 assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); 196 Set<Prefix> prefixes = service.getPrefixes(MetricPrefix.class); 197 assertNotNull("Section " + SECTION + ": Metric Prefixes are null", prefixes); 198 assertFalse("Section " + SECTION + " No Metric Prefixes found", prefixes.isEmpty()); 199 assertEquals(20, prefixes.size(), "Section " + SECTION + " Wrong Number of Metric Prefixes"); 200 } 201 } 202}