You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by rm...@apache.org on 2018/11/05 09:53:46 UTC

bval git commit: adding LiskovTest in ignored more to share the work to do on Liskov + some minor tweaks in tck (mainly logging and fixing a wrong license)

Repository: bval
Updated Branches:
  refs/heads/master 8084d4d79 -> 9171e1cdc


adding LiskovTest in ignored more to share the work to do on Liskov + some minor tweaks in tck (mainly logging and fixing a wrong license)


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/9171e1cd
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/9171e1cd
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/9171e1cd

Branch: refs/heads/master
Commit: 9171e1cdca0ccac946a27874417b8b43ec4e5282
Parents: 8084d4d
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Mon Nov 5 10:53:37 2018 +0100
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Mon Nov 5 10:53:37 2018 +0100

----------------------------------------------------------------------
 .../java/org/apache/bval/jsr/LiskovTest.java    | 59 ++++++++++++++++++++
 bval-tck/pom.xml                                |  4 ++
 .../arquillian/BValArquillianExtension.java     | 26 ++++++++-
 .../org/apache/bval/arquillian/EJBEnricher.java | 32 ++++++-----
 .../apache/bval/arquillian/LogTckFormatter.java | 41 ++++++++++++++
 bval-tck/src/test/resources/logging.properties  | 21 +++++++
 6 files changed, 167 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/9171e1cd/bval-jsr/src/test/java/org/apache/bval/jsr/LiskovTest.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/LiskovTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/LiskovTest.java
new file mode 100644
index 0000000..9f40d0c
--- /dev/null
+++ b/bval-jsr/src/test/java/org/apache/bval/jsr/LiskovTest.java
@@ -0,0 +1,59 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.bval.jsr;
+
+import java.lang.reflect.Method;
+
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.NotNull;
+import javax.validation.executable.ExecutableValidator;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore("requires some revisiting of Liskov impl - discuss in progress")
+public class LiskovTest {
+    @Test // this test was throwing a Liskov exception, here to ensure it is not the case
+    public void validateParams() throws NoSuchMethodException {
+        final Api service = new Impl();
+        try (final ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
+            final ExecutableValidator validator = factory.getValidator().forExecutables();
+            final Method method = Api.class.getMethod("read", String.class);
+            validator.validateParameters(service, method, new Object[]{""});
+        }
+    }
+
+    public interface Api {
+        String read(@NotNull String key);
+    }
+
+    public static abstract class Base {
+        public String read(final String key) {
+            return null;
+        }
+    }
+
+    public static class Impl extends Base implements Api {
+        @Override
+        public String read(final String key) {
+            return super.read(key);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/bval/blob/9171e1cd/bval-tck/pom.xml
----------------------------------------------------------------------
diff --git a/bval-tck/pom.xml b/bval-tck/pom.xml
index f2a0cd0..9ff0045 100644
--- a/bval-tck/pom.xml
+++ b/bval-tck/pom.xml
@@ -182,6 +182,10 @@ under the License.
                                     <name>includeJavaFXTests</name>
                                     <value>true</value>
                                 </property>
+                                <property>
+                                    <name>java.util.logging.config.file</name>
+                                    <value>${project.basedir}/src/test/resources/logging.properties</value>
+                                </property>
                             </systemProperties>
                             <parallel>methods</parallel>
                             <threadCount>4</threadCount>

http://git-wip-us.apache.org/repos/asf/bval/blob/9171e1cd/bval-tck/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java
----------------------------------------------------------------------
diff --git a/bval-tck/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java b/bval-tck/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java
index 7ad860c..be051ea 100644
--- a/bval-tck/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java
+++ b/bval-tck/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java
@@ -18,11 +18,35 @@
  */
 package org.apache.bval.arquillian;
 
+import java.util.logging.Logger;
+
+import org.jboss.arquillian.core.api.annotation.Observes;
 import org.jboss.arquillian.core.spi.LoadableExtension;
+import org.jboss.arquillian.test.spi.TestClass;
 import org.jboss.arquillian.test.spi.TestEnricher;
+import org.jboss.arquillian.test.spi.event.suite.AfterClass;
+import org.jboss.arquillian.test.spi.event.suite.BeforeClass;
 
 public class BValArquillianExtension implements LoadableExtension {
     public void register(final ExtensionBuilder builder) {
-        builder.service(TestEnricher.class, EJBEnricher.class);
+        builder.service(TestEnricher.class, EJBEnricher.class).observer(TestLogger.class);
+    }
+
+    public static class TestLogger {
+        private static final Logger LOGGER = Logger.getLogger(TestLogger.class.getName());
+
+        public void before(@Observes final BeforeClass beforeClass) {
+            LOGGER.info(() -> "Launching " + toName(beforeClass.getTestClass()));
+        }
+
+        public void after(@Observes final AfterClass beforeClass) {
+            LOGGER.info(() -> "Executed " + toName(beforeClass.getTestClass()));
+        }
+
+        private String toName(final TestClass testClass) {
+            return testClass.getJavaClass()
+                            .getName()
+                            .replace("org.hibernate.beanvalidation.tck.tests.", "o.h.b.t.t.");
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/bval/blob/9171e1cd/bval-tck/src/main/java/org/apache/bval/arquillian/EJBEnricher.java
----------------------------------------------------------------------
diff --git a/bval-tck/src/main/java/org/apache/bval/arquillian/EJBEnricher.java b/bval-tck/src/main/java/org/apache/bval/arquillian/EJBEnricher.java
index da55ba5..61254a7 100644
--- a/bval-tck/src/main/java/org/apache/bval/arquillian/EJBEnricher.java
+++ b/bval-tck/src/main/java/org/apache/bval/arquillian/EJBEnricher.java
@@ -1,19 +1,21 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.bval.arquillian;
 
 import org.jboss.arquillian.test.spi.TestEnricher;

http://git-wip-us.apache.org/repos/asf/bval/blob/9171e1cd/bval-tck/src/main/java/org/apache/bval/arquillian/LogTckFormatter.java
----------------------------------------------------------------------
diff --git a/bval-tck/src/main/java/org/apache/bval/arquillian/LogTckFormatter.java b/bval-tck/src/main/java/org/apache/bval/arquillian/LogTckFormatter.java
new file mode 100644
index 0000000..f722773
--- /dev/null
+++ b/bval-tck/src/main/java/org/apache/bval/arquillian/LogTckFormatter.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.arquillian;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+
+public class LogTckFormatter extends SimpleFormatter {
+    @Override
+    public String format(final LogRecord record) {
+        final String message = formatMessage(record);
+        String throwable = "";
+        if (record.getThrown() != null) {
+            final StringWriter sw = new StringWriter();
+            final PrintWriter pw = new PrintWriter(sw);
+            pw.println();
+            record.getThrown().printStackTrace(pw);
+            pw.close();
+            throwable = sw.toString();
+        }
+        return String.format("[%s] %s%n%s", record.getLevel(), message, throwable);
+    }
+}

http://git-wip-us.apache.org/repos/asf/bval/blob/9171e1cd/bval-tck/src/test/resources/logging.properties
----------------------------------------------------------------------
diff --git a/bval-tck/src/test/resources/logging.properties b/bval-tck/src/test/resources/logging.properties
new file mode 100644
index 0000000..339a08c
--- /dev/null
+++ b/bval-tck/src/test/resources/logging.properties
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+.level= INFO
+handlers = java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level = INFO
+java.util.logging.ConsoleHandler.formatter =org.apache.bval.arquillian.LogTckFormatter
+org.apache.webbeans.arquillian.standalone.OwbArquillianScannerService.level = WARNING