{@code - * abstract class Shape { - * int x; - * int y; - * } - * class Circle extends Shape { - * int radius; - * } - * class Rectangle extends Shape { - * int width; - * int height; - * } - * class Diamond extends Shape { - * int width; - * int height; - * } - * class Drawing { - * Shape bottomShape; - * Shape topShape; - * } - * }- *
Without additional type information, the serialized JSON is ambiguous. Is - * the bottom shape in this drawing a rectangle or a diamond?
{@code - * { - * "bottomShape": { - * "width": 10, - * "height": 5, - * "x": 0, - * "y": 0 - * }, - * "topShape": { - * "radius": 2, - * "x": 4, - * "y": 1 - * } - * }}- * This class addresses this problem by adding type information to the - * serialized JSON and honoring that type information when the JSON is - * deserialized:
{@code - * { - * "bottomShape": { - * "type": "Diamond", - * "width": 10, - * "height": 5, - * "x": 0, - * "y": 0 - * }, - * "topShape": { - * "type": "Circle", - * "radius": 2, - * "x": 4, - * "y": 1 - * } - * }}- * Both the type field name ({@code "type"}) and the type labels ({@code - * "Rectangle"}) are configurable. - * - *
{@code - * RuntimeTypeAdapterFactory- * Next register all of your subtypes. Every subtype must be explicitly - * registered. This protects your application from injection attacks. If you - * don't supply an explicit type label, the type's simple name will be used. - *shapeAdapterFactory - * = RuntimeTypeAdapterFactory.of(Shape.class, "type"); - * }
{@code - * shapeAdapter.registerSubtype(Rectangle.class, "Rectangle"); - * shapeAdapter.registerSubtype(Circle.class, "Circle"); - * shapeAdapter.registerSubtype(Diamond.class, "Diamond"); - * }- * Finally, register the type adapter factory in your application's GSON builder: - *
{@code - * Gson gson = new GsonBuilder() - * .registerTypeAdapterFactory(shapeAdapterFactory) - * .create(); - * }- * Like {@code GsonBuilder}, this API supports chaining:
{@code - * RuntimeTypeAdapterFactory- */ -public final class RuntimeTypeAdapterFactoryshapeAdapterFactory = RuntimeTypeAdapterFactory.of(Shape.class) - * .registerSubtype(Rectangle.class) - * .registerSubtype(Circle.class) - * .registerSubtype(Diamond.class); - * }
+ * { + * @code + * abstract class Shape { + * int x; + * int y; + * } + * class Circle extends Shape { + * int radius; + * } + * class Rectangle extends Shape { + * int width; + * int height; + * } + * class Diamond extends Shape { + * int width; + * int height; + * } + * class Drawing { + * Shape bottomShape; + * Shape topShape; + * } + * } + *+ *
+ * Without additional type information, the serialized JSON is ambiguous. Is + * the bottom shape in this drawing a rectangle or a diamond? + * + *
+ * {@code + * { + * "bottomShape": { + * "width": 10, + * "height": 5, + * "x": 0, + * "y": 0 + * }, + * "topShape": { + * "radius": 2, + * "x": 4, + * "y": 1 + * } + * }} + *+ * + * This class addresses this problem by adding type information to the + * serialized JSON and honoring that type information when the JSON is + * deserialized: + * + *
+ * {@code + * { + * "bottomShape": { + * "type": "Diamond", + * "width": 10, + * "height": 5, + * "x": 0, + * "y": 0 + * }, + * "topShape": { + * "type": "Circle", + * "radius": 2, + * "x": 4, + * "y": 1 + * } + * }} + *+ * + * Both the type field name ({@code "type"}) and the type labels ({@code + * "Rectangle"}) are configurable. + * + *
+ * { + * @code + * RuntimeTypeAdapterFactory+ * + * Next register all of your subtypes. Every subtype must be explicitly + * registered. This protects your application from injection attacks. If you + * don't supply an explicit type label, the type's simple name will be used. + * + *shapeAdapterFactory = RuntimeTypeAdapterFactory.of(Shape.class, "type"); + * } + *
+ * {@code + * shapeAdapter.registerSubtype(Rectangle.class, "Rectangle"); + * shapeAdapter.registerSubtype(Circle.class, "Circle"); + * shapeAdapter.registerSubtype(Diamond.class, "Diamond"); + * } + *+ * + * Finally, register the type adapter factory in your application's GSON builder: + * + *
+ * { + * @code + * Gson gson = new GsonBuilder().registerTypeAdapterFactory(shapeAdapterFactory).create(); + * } + *+ * + * Like {@code GsonBuilder}, this API supports chaining: + * + *
+ * { + * @code + * RuntimeTypeAdapterFactory+ * + * @author Christophe Bornet - Initial contribution + */ +@NonNullByDefault +public final class RuntimeTypeAdapterFactoryshapeAdapterFactory = RuntimeTypeAdapterFactory.of(Shape.class) + * .registerSubtype(Rectangle.class).registerSubtype(Circle.class).registerSubtype(Diamond.class); + * } + *
@@ -63,12 +62,16 @@ import org.openhab.binding.lametrictime.api.test.TestUtil; * either execute the test via your IDE or run 'mvn -DskipITs=false * integration-test'. *
+ * + * @author Gregory Moyer - Initial contribution */ @Disabled +@NonNullByDefault public class LaMetricTimeLocalImplIT { private static final String PROP_HOST = "host"; private static final String PROP_API_KEY = "apiKey"; + @Nullable private static LaMetricTimeLocalImpl local; @BeforeAll @@ -225,8 +228,8 @@ public class LaMetricTimeLocalImplIT { local.getNotifications().stream().forEach(n -> { try { local.deleteNotification(n.getId()); - } catch (Exception e) { - e.printStackTrace(); + } catch (NotificationNotFoundException e) { + // ignore } }); @@ -245,7 +248,7 @@ public class LaMetricTimeLocalImplIT { return new Notification().withPriority(Priority.CRITICAL.toRaw()).withModel(new NotificationModel() .withCycles(cycles) .withSound(new Sound().withCategory(SoundCategory.NOTIFICATIONS.toRaw()) - .withId(org.openhab.binding.lametrictime.api.model.enums.Sound.CAT.toRaw())) + .withId(org.openhab.binding.lametrictime.internal.api.dto.enums.Sound.CAT.toRaw())) .withFrames(Arrays.asList(new Frame().withText("CAT!").withIcon( "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAUklEQVQYlWNUVFBgYGBgYBC98uE/AxJ4rSPAyMDAwMCETRJZjAnGgOlAZote+fCfCV0nOmA0+yKAYTwygJuAzQoGBgYGRkUFBQZ0dyDzGQl5EwCTESNpFb6zEwAAAABJRU5ErkJggg==")))); } diff --git a/bundles/org.openhab.binding.lametrictime/src/test/java/org/openhab/binding/lametrictime/internal/api/test/AbstractTest.java b/bundles/org.openhab.binding.lametrictime/src/test/java/org/openhab/binding/lametrictime/internal/api/test/AbstractTest.java new file mode 100644 index 000000000..1ba9dcbde --- /dev/null +++ b/bundles/org.openhab.binding.lametrictime/src/test/java/org/openhab/binding/lametrictime/internal/api/test/AbstractTest.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.lametrictime.internal.api.test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * abstract test class. + * + * @author Gregory Moyer - Initial contribution + */ +@NonNullByDefault +public abstract class AbstractTest { + protected File getTestDataFile(String name) { + return getTestDataPath(name).toFile(); + } + + protected Path getTestDataPath(String name) { + return TestUtil.getTestDataPath(this.getClass(), name); + } + + protected String readJson(String jsonFileName) throws IOException { + return String.join("\n", Files.readAllLines(getTestDataPath(jsonFileName))); + } +} diff --git a/bundles/org.openhab.binding.lametrictime/src/test/java/org/openhab/binding/lametrictime/internal/api/test/TestUtil.java b/bundles/org.openhab.binding.lametrictime/src/test/java/org/openhab/binding/lametrictime/internal/api/test/TestUtil.java new file mode 100644 index 000000000..b290072ff --- /dev/null +++ b/bundles/org.openhab.binding.lametrictime/src/test/java/org/openhab/binding/lametrictime/internal/api/test/TestUtil.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.lametrictime.internal.api.test; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * Test utility class. + * + * @author Gregory Moyer - Initial contribution + */ +@NonNullByDefault +public class TestUtil { + private static final String RESOURCES_PATH = "src/test/resources/"; + + public static Path getTestDataPath(Class> clazz, String name) { + String packageName = clazz.getPackage().getName(); + + List