-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* preparation for upcoming sql reimplementation ( #101 ) * implementation of settings for observer properties * implementation of observer properties * implementation of JsonSerializationObserver * added unit test; update documentation * review fixes
- Loading branch information
1 parent
2d18736
commit 07840f4
Showing
32 changed files
with
620 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
*.class | ||
/target/ | ||
/pom.xml~ | ||
/.settings/ | ||
/.classpath | ||
/.project | ||
/.yardoc | ||
/tmp | ||
/pombak/ | ||
/.sonar_lock | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
.DS_Store | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
*.class | ||
/target/ | ||
/pom.xml~ | ||
/.settings/ | ||
/.classpath | ||
/.project | ||
/.yardoc | ||
/tmp | ||
/pombak/ | ||
/.sonar_lock | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
.DS_Store | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...c/main/java/de/braintags/vertx/jomnigate/testdatastore/TestJsonSerializationObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* #%L | ||
* vertx-pojo-mapper-common-test | ||
* %% | ||
* Copyright (C) 2017 Braintags GmbH | ||
* %% | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* #L% | ||
*/ | ||
package de.braintags.vertx.jomnigate.testdatastore; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
import org.junit.Test; | ||
|
||
import de.braintags.vertx.jomnigate.init.DataStoreSettings; | ||
import de.braintags.vertx.jomnigate.init.ObserverDefinition; | ||
import de.braintags.vertx.jomnigate.observer.ObserverEventType; | ||
import de.braintags.vertx.jomnigate.observer.impl.JsonSerializationObserver; | ||
import de.braintags.vertx.jomnigate.testdatastore.mapper.SimpleMapper; | ||
import io.vertx.core.json.Json; | ||
import io.vertx.ext.unit.TestContext; | ||
|
||
/** | ||
* Tests to improve correct mapping information for defined observers ( or by settings or annotation ) | ||
* | ||
* @author Michael Remme | ||
* | ||
*/ | ||
public class TestJsonSerializationObserver extends AbstractObserverTest { | ||
private static final io.vertx.core.logging.Logger LOGGER = io.vertx.core.logging.LoggerFactory | ||
.getLogger(TestJsonSerializationObserver.class); | ||
|
||
@Test | ||
public void testAfterInsertAndUpdate(TestContext context) throws IOException { | ||
File logDir = getLogDir(); | ||
DataStoreSettings settings = getDataStore(context).getSettings(); | ||
ObserverDefinition<JsonSerializationObserver> os = new ObserverDefinition<>(JsonSerializationObserver.class); | ||
os.getEventTypeList().add(ObserverEventType.AFTER_INSERT); | ||
os.getEventTypeList().add(ObserverEventType.AFTER_UPDATE); | ||
os.getObserverProperties().setProperty(JsonSerializationObserver.DIRECTORY_PROPERTY, logDir.getAbsolutePath()); | ||
settings.getObserverSettings().add(os); | ||
|
||
SimpleMapper sm = new SimpleMapper("testname", "nix"); | ||
sm.intValue = -1; | ||
saveRecord(context, sm); | ||
sm.intValue = 5; | ||
sm.name = "newNAME"; | ||
saveRecord(context, sm); | ||
checkResult(context, logDir, 2, 500); | ||
} | ||
|
||
@Test | ||
public void testAfterInsert(TestContext context) throws IOException { | ||
File logDir = getLogDir(); | ||
DataStoreSettings settings = getDataStore(context).getSettings(); | ||
ObserverDefinition<JsonSerializationObserver> os = new ObserverDefinition<>(JsonSerializationObserver.class); | ||
os.getEventTypeList().add(ObserverEventType.AFTER_INSERT); | ||
os.getObserverProperties().setProperty(JsonSerializationObserver.DIRECTORY_PROPERTY, logDir.getAbsolutePath()); | ||
settings.getObserverSettings().add(os); | ||
LOGGER.debug(Json.encodePrettily(os)); | ||
SimpleMapper sm = new SimpleMapper("testname", "nix"); | ||
sm.intValue = -1; | ||
saveRecord(context, sm); | ||
checkResult(context, logDir, 1, 500); | ||
} | ||
|
||
@Test | ||
public void testDirectoryNotSet(TestContext context) throws IOException { | ||
File logDir = getLogDir(); | ||
DataStoreSettings settings = getDataStore(context).getSettings(); | ||
ObserverDefinition<JsonSerializationObserver> os = new ObserverDefinition<>(JsonSerializationObserver.class); | ||
os.getEventTypeList().add(ObserverEventType.AFTER_INSERT); | ||
settings.getObserverSettings().add(os); | ||
SimpleMapper sm = new SimpleMapper("testname", "nix"); | ||
sm.intValue = -1; | ||
try { | ||
saveRecord(context, sm); | ||
context.fail("we are expecting an exception, cause the log directory is not set"); | ||
} catch (Throwable e) { | ||
// we expect this | ||
} | ||
} | ||
|
||
private void checkResult(TestContext context, File logDir, int fileCount, long waitTicks) { | ||
long start = System.currentTimeMillis(); | ||
while (System.currentTimeMillis() - start < waitTicks) { | ||
File[] files = logDir.listFiles((dir, fileName) -> fileName.endsWith("json")); | ||
if (files.length >= fileCount) { | ||
break; | ||
} | ||
} | ||
context.assertEquals(fileCount, logDir.listFiles((dir, fileName) -> fileName.endsWith("json")).length, | ||
"expected files to be created"); | ||
} | ||
|
||
private File getLogDir() throws IOException { | ||
File logDir = Files.createTempDirectory("jsonSerDirTmp").toFile(); | ||
File[] fl = logDir.listFiles(); | ||
for (File f : fl) { | ||
f.delete(); | ||
} | ||
if (logDir.listFiles().length > 0) { | ||
throw new IllegalArgumentException("the directory was not cleaned"); | ||
} | ||
logDir.mkdir(); | ||
LOGGER.debug("FILE CREATION IN " + logDir.getAbsolutePath()); | ||
return logDir; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...braintags/vertx/jomnigate/testdatastore/mapper/ObserverAnnotatedMapperWithProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* #%L | ||
* vertx-pojo-mapper-common-test | ||
* %% | ||
* Copyright (C) 2017 Braintags GmbH | ||
* %% | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* #L% | ||
*/ | ||
package de.braintags.vertx.jomnigate.testdatastore.mapper; | ||
|
||
import de.braintags.vertx.jomnigate.annotation.Observer; | ||
import de.braintags.vertx.jomnigate.annotation.ObserverOption; | ||
import de.braintags.vertx.jomnigate.testdatastore.mapper.typehandler.BaseRecord; | ||
import de.braintags.vertx.jomnigate.testdatastore.observer.TestObserver; | ||
|
||
/** | ||
* | ||
* | ||
* @author Michael Remme | ||
* | ||
*/ | ||
@Observer(observerClass = TestObserver.class, priority = 600, observerOptions = { | ||
@ObserverOption(key = "testKey", value = "testValue") }) | ||
public class ObserverAnnotatedMapperWithProperties extends BaseRecord { | ||
|
||
/** | ||
* | ||
*/ | ||
public ObserverAnnotatedMapperWithProperties() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.