|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + * |
| 19 | + */ |
| 20 | +package de.bitctrl.dav.rest.client.converter; |
| 21 | + |
| 22 | +import java.io.File; |
| 23 | +import java.time.LocalDateTime; |
| 24 | +import java.time.ZoneId; |
| 25 | +import java.util.Arrays; |
| 26 | +import java.util.Collection; |
| 27 | + |
| 28 | +import org.junit.AfterClass; |
| 29 | +import org.junit.Assert; |
| 30 | +import org.junit.BeforeClass; |
| 31 | +import org.junit.Test; |
| 32 | +import org.junit.runner.RunWith; |
| 33 | +import org.junit.runners.Parameterized; |
| 34 | +import org.junit.runners.Parameterized.Parameter; |
| 35 | +import org.junit.runners.Parameterized.Parameters; |
| 36 | + |
| 37 | +import de.bitctrl.dav.rest.api.model.VerkehrsdatenKurzzeit; |
| 38 | +import de.bsvrz.dav.daf.communication.dataRepresentation.AttributeBaseValueDataFactory; |
| 39 | +import de.bsvrz.dav.daf.communication.dataRepresentation.AttributeHelper; |
| 40 | +import de.bsvrz.dav.daf.main.Data; |
| 41 | +import de.bsvrz.dav.daf.main.DataDescription; |
| 42 | +import de.bsvrz.dav.daf.main.ResultData; |
| 43 | +import de.bsvrz.dav.daf.main.config.Aspect; |
| 44 | +import de.bsvrz.dav.daf.main.config.AttributeGroup; |
| 45 | +import de.bsvrz.dav.daf.main.config.SystemObject; |
| 46 | +import de.bsvrz.puk.config.configFile.datamodel.ConfigDataModel; |
| 47 | + |
| 48 | +/** |
| 49 | + * Tests zur Konvertierung von Verkehrdaten der Attributgruppe |
| 50 | + * "atg.verkehrsDatenKurzZeitFs" eines Fahrstreifens in das JSON Modell. |
| 51 | + * |
| 52 | + * @author BitCtrl Systems GmbH, ChHoesel |
| 53 | + * |
| 54 | + */ |
| 55 | +@RunWith(Parameterized.class) |
| 56 | +public class VerkehrsDatenKurzZeitIntervallFSConverterTest { |
| 57 | + |
| 58 | + private static ConfigDataModel dataModel; |
| 59 | + |
| 60 | + @BeforeClass |
| 61 | + public static void setUpBeforeClass() throws Exception { |
| 62 | + final File konfiguration = new File("src/test/resources/konfiguration/verwaltungsdaten.xml"); |
| 63 | + dataModel = new ConfigDataModel(konfiguration); |
| 64 | + } |
| 65 | + |
| 66 | + @AfterClass |
| 67 | + public static void tearDownAfterClass() throws Exception { |
| 68 | + dataModel.close(); |
| 69 | + } |
| 70 | + |
| 71 | + @Parameters(name = "{index}: anzahl->{0}, geschwindigkeit->{1}, guete->{2}, datum->{3}, belegung->{4}, asp->{5}") |
| 72 | + public static Collection<Object[]> data() { |
| 73 | + |
| 74 | + return Arrays.asList(new Object[][] { |
| 75 | + // anahl Fz, geschwindigkeit, güte, datum, belegung |
| 76 | + { -3, -3, 0.2d, LocalDateTime.of(2019, 1, 1, 0, 0), 0,"asp.externeErfassung","" }, |
| 77 | + { 3, 3, 0.9d, LocalDateTime.of(2019, 1, 1, 0, 0), 1,"asp.externeErfassung","Fz/Intervall" }, |
| 78 | + { -2, -2, 0.999d, LocalDateTime.of(2019, 12, 31, 23, 59), 1 ,"asp.messWertErsetzung",""}, |
| 79 | + { 2, 2, 0.999d, LocalDateTime.of(2019, 12, 31, 23, 59), 1 ,"asp.messWertErsetzung","Fz/Intervall"}, |
| 80 | + { -2, -2, 0.0, LocalDateTime.of(2019, 3, 31, 2, 0), 99 ,"asp.plausibilitätsPrüfungFormal",""}, |
| 81 | + { 2, 2, 0.0, LocalDateTime.of(2019, 3, 31, 2, 0), 99 ,"asp.plausibilitätsPrüfungFormal","Fz/Intervall"}, |
| 82 | + { -1, -1, 1d, LocalDateTime.of(2019, 2, 28, 12, 0), 100 ,"asp.plausibilitätsPrüfungLogisch",""}, |
| 83 | + { 1, 1, 1d, LocalDateTime.of(2019, 2, 28, 12, 0), 100 ,"asp.plausibilitätsPrüfungLogisch","Fz/Intervall"}, |
| 84 | + { 0, 0, 0.5d, LocalDateTime.of(2019, 9, 27, 12, 0), 1 ,"asp.plausibilitätsPrüfungFormal","Fz/Intervall"}, |
| 85 | + { 100, 254, 0.5d, LocalDateTime.of(2019, 3, 14, 12, 0), 55,"asp.plausibilitätsPrüfungLogisch","Fz/Intervall" }, |
| 86 | + { 30, 111, 1d, LocalDateTime.of(2020, 2, 10, 12, 0), 12,"asp.externeErfassung","Fz/Intervall" }, |
| 87 | + { 45, 22, 0.1d, LocalDateTime.of(2020,1, 10, 12, 0), 33,"asp.messWertErsetzung","Fz/Intervall" } |
| 88 | + |
| 89 | + }); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + @Parameter(0) |
| 94 | + public int anzahl; |
| 95 | + |
| 96 | + @Parameter(1) |
| 97 | + public int geschwindigkeit; |
| 98 | + |
| 99 | + @Parameter(2) |
| 100 | + public double guete; |
| 101 | + |
| 102 | + @Parameter(3) |
| 103 | + public LocalDateTime time; |
| 104 | + |
| 105 | + @Parameter(4) |
| 106 | + public int belegung; |
| 107 | + |
| 108 | + @Parameter(5) |
| 109 | + public String aspPid; |
| 110 | + |
| 111 | + @Parameter(6) |
| 112 | + public String dimension; |
| 113 | + |
| 114 | + @Test |
| 115 | + public void test() { |
| 116 | + final SystemObject fs = dataModel.getObject("test.fs1"); |
| 117 | + final AttributeGroup atg = dataModel.getAttributeGroup("atg.verkehrsDatenKurzZeitIntervall"); |
| 118 | + final Aspect asp = dataModel.getAspect(aspPid); |
| 119 | + |
| 120 | + final Data data = AttributeBaseValueDataFactory.createAdapter(atg, AttributeHelper.getAttributesValues(atg)); |
| 121 | + data.getItem("qKfz").getUnscaledValue("Wert").set(anzahl); |
| 122 | + data.getItem("qKfz").getItem("Güte").getScaledValue("Index").set(guete); |
| 123 | + data.getItem("vKfz").getUnscaledValue("Wert").set(geschwindigkeit); |
| 124 | + data.getItem("vKfz").getItem("Güte").getScaledValue("Index").set(guete); |
| 125 | + data.getItem("qLkw").getUnscaledValue("Wert").set(anzahl); |
| 126 | + data.getItem("qLkw").getItem("Güte").getScaledValue("Index").set(guete); |
| 127 | + data.getItem("vLkw").getUnscaledValue("Wert").set(geschwindigkeit); |
| 128 | + data.getItem("vLkw").getItem("Güte").getScaledValue("Index").set(guete); |
| 129 | + data.getItem("qPkw").getUnscaledValue("Wert").set(anzahl); |
| 130 | + data.getItem("qPkw").getItem("Güte").getScaledValue("Index").set(guete); |
| 131 | + data.getItem("vPkw").getUnscaledValue("Wert").set(geschwindigkeit); |
| 132 | + data.getItem("vPkw").getItem("Güte").getScaledValue("Index").set(guete); |
| 133 | + data.getItem("b").getScaledValue("Wert").set(belegung / 1000d); |
| 134 | + |
| 135 | + final ResultData rd = new ResultData(fs, new DataDescription(atg, asp), |
| 136 | + time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), data); |
| 137 | + |
| 138 | + |
| 139 | + final VerkehrsDatenKurzZeitIntervallFSConverter converter = new VerkehrsDatenKurzZeitIntervallFSConverter(); |
| 140 | + final VerkehrsdatenKurzzeit result = converter.dav2Json(rd).iterator().next(); |
| 141 | + |
| 142 | + Assert.assertEquals(anzahl, result.getQKfz().getWert()); |
| 143 | + Assert.assertEquals(dimension, result.getQKfz().getDimension()); |
| 144 | + Assert.assertEquals(anzahl, result.getQLkw().getWert()); |
| 145 | + Assert.assertEquals(dimension, result.getQLkw().getDimension()); |
| 146 | + Assert.assertEquals(anzahl, result.getQPkw().getWert()); |
| 147 | + Assert.assertEquals(dimension, result.getQPkw().getDimension()); |
| 148 | + Assert.assertEquals(geschwindigkeit, result.getVKfz().getWert()); |
| 149 | + Assert.assertEquals(geschwindigkeit, result.getVLkw().getWert()); |
| 150 | + Assert.assertEquals(geschwindigkeit, result.getVPkw().getWert()); |
| 151 | + Assert.assertEquals(guete, result.getQKfz().getGuete()); |
| 152 | + Assert.assertEquals(guete, result.getQLkw().getGuete()); |
| 153 | + Assert.assertEquals(guete, result.getQPkw().getGuete()); |
| 154 | + } |
| 155 | + |
| 156 | +} |
0 commit comments