You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/09/17 19:10:25 UTC

[isis] branch v2 updated (796c9e1 -> e19af26)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a change to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git.


    from 796c9e1  ISIS-1976: further remove guava
     new 60cc330  ISIS-1976: fixing tests, also remove some unused test code
     new e19af26  ISIS-1976: adding another test for RequestScope support

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../core/metamodel/services/ServicesInjector.java  |  48 +++---
 .../core/commons/lang/ListUtilsTest_adjust.java    |  10 +-
 .../core/commons/lang/ListUtilsTest_insert.java    |   8 +-
 .../collections/JavaCollectionFacetTest.java       |  16 +-
 .../services/ServicesInjectorDefaultTest.java      |  11 ++
 .../runtime/services/ServicesInstallerUtils.java   |   7 +-
 .../runtime/services/DeweyOrderComparatorTest.java | 116 --------------
 .../isis/core/runtime/services/DeweyOrderUtil.java | 168 ---------------------
 .../core/runtime/services/DeweyOrderUtilTest.java  | 113 --------------
 .../runtime/services/ServiceInstantiatorTest.java  |   8 +-
 .../ServiceInjectorTestUsingCodegenPlugin.java     | 153 +++++++++++++++++++
 .../ServiceInstantiatorTestUsingCodegenPlugin.java |  11 +-
 12 files changed, 213 insertions(+), 456 deletions(-)
 delete mode 100644 core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderComparatorTest.java
 delete mode 100644 core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtil.java
 delete mode 100644 core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtilTest.java
 create mode 100644 core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInjectorTestUsingCodegenPlugin.java


[isis] 01/02: ISIS-1976: fixing tests, also remove some unused test code

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 60cc330da3b1dfd7cbc5ba0cd94f5572fcfd37c8
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Sep 17 19:46:02 2018 +0200

    ISIS-1976: fixing tests, also remove some unused test code
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
 .../core/commons/lang/ListUtilsTest_adjust.java    |  10 +-
 .../core/commons/lang/ListUtilsTest_insert.java    |   8 +-
 .../collections/JavaCollectionFacetTest.java       |  16 +-
 .../runtime/services/ServicesInstallerUtils.java   |   7 +-
 .../runtime/services/DeweyOrderComparatorTest.java | 116 --------------
 .../isis/core/runtime/services/DeweyOrderUtil.java | 168 ---------------------
 .../core/runtime/services/DeweyOrderUtilTest.java  | 113 --------------
 .../runtime/services/ServiceInstantiatorTest.java  |   9 +-
 8 files changed, 20 insertions(+), 427 deletions(-)

diff --git a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java
index 5b6e05a..49ff2b6 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_adjust.java
@@ -20,18 +20,18 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.junit.Test;
 
-import org.apache.isis.commons.internal.collections._Lists;
-
 public class ListUtilsTest_adjust {
     
     
     @Test
     public void sameLength() throws Exception {
-        final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+        final List<Integer> list = Arrays.asList(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
         ListExtensions.adjust(list, 3);
         
         assertThat(list.size(), is(3));
@@ -42,7 +42,7 @@ public class ListUtilsTest_adjust {
     
     @Test
     public void ifLonger() throws Exception {
-        final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+        final List<Integer> list = new ArrayList<>(Arrays.asList(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
         ListExtensions.adjust(list, 4);
         
         assertThat(list.size(), is(4));
@@ -54,7 +54,7 @@ public class ListUtilsTest_adjust {
     
     @Test
     public void ifShorter() throws Exception {
-        final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+        final List<Integer> list = new ArrayList<>(Arrays.asList(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
         ListExtensions.adjust(list, 2);
         
         assertThat(list.size(), is(2));
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java
index a1d899f..f37703e 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/commons/lang/ListUtilsTest_insert.java
@@ -30,7 +30,7 @@ public class ListUtilsTest_insert {
     
     @Test
     public void insert_whenInsertionPointAtBeginning() throws Exception {
-        final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+        final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
         ListExtensions.insert(list, 0, Integer.valueOf(10));
         
         assertThat(list.size(), is(4));
@@ -42,7 +42,7 @@ public class ListUtilsTest_insert {
     
     @Test
     public void insert_whenInsertionPointInMiddle() throws Exception {
-        final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+        final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
         ListExtensions.insert(list, 1, Integer.valueOf(10));
         
         assertThat(list.size(), is(4));
@@ -54,7 +54,7 @@ public class ListUtilsTest_insert {
 
     @Test
     public void insert_whenInsertionPointAtEnd() throws Exception {
-        final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+        final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
         ListExtensions.insert(list, 3, Integer.valueOf(10));
         
         assertThat(list.size(), is(4));
@@ -66,7 +66,7 @@ public class ListUtilsTest_insert {
     
     @Test
     public void insert_whenInsertionPointBeyondEnd() throws Exception {
-        final List<Integer> list = _Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE);
+        final List<Integer> list = _Lists.newArrayList(_Lists.of(Integer.valueOf(0), Integer.MAX_VALUE, Integer.MIN_VALUE));
         ListExtensions.insert(list, 4, Integer.valueOf(10));
         
         assertThat(list.size(), is(5));
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java
index 2eceedc..9300746 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/collections/JavaCollectionFacetTest.java
@@ -24,7 +24,7 @@ import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
 import java.util.Collection;
-import java.util.Iterator;
+import java.util.stream.Stream;
 
 import org.jmock.Expectations;
 import org.jmock.auto.Mock;
@@ -54,15 +54,13 @@ public class JavaCollectionFacetTest {
     @Mock
     private Collection<ObjectAdapter> mockWrappedCollection;
     @Mock
-    private Iterator<ObjectAdapter> mockIterator;
-    @Mock
-    private ObjectAdapterProvider mockAdapterManager;
+    private ObjectAdapterProvider mockOAProvider;
 
     @Before
     public void setUp() throws Exception {
-        mockAdapterManager = context.mock(ObjectAdapterProvider.class);
+        mockOAProvider = context.mock(ObjectAdapterProvider.class);
 
-        facet = new JavaCollectionFacet(mockFacetHolder, mockAdapterManager);
+        facet = new JavaCollectionFacet(mockFacetHolder, mockOAProvider);
     }
 
     @After
@@ -77,11 +75,9 @@ public class JavaCollectionFacetTest {
                 oneOf(mockCollection).getObject();
                 will(returnValue(mockWrappedCollection));
 
-                oneOf(mockWrappedCollection).iterator();
-                will(returnValue(mockIterator));
+                oneOf(mockWrappedCollection).stream();
+                will(returnValue(Stream.empty()));
 
-                oneOf(mockIterator).hasNext();
-                will(returnValue(false));
             }
         });
         assertThat(facet.firstElement(mockCollection), is(nullValue()));
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java
index c347d07..574981b 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServicesInstallerUtils.java
@@ -91,12 +91,7 @@ final class ServicesInstallerUtils  {
     }
 
     private static Function<String, Object> instantiator(final ServiceInstantiator serviceInstantiator) {
-        return new Function<String, Object>() {
-            @Override
-            public Object apply(String serviceName) {
-                return instantiateService(serviceName, serviceInstantiator);
-            }
-        };
+        return (String serviceName) -> instantiateService(serviceName, serviceInstantiator);
     }
 
 }
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderComparatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderComparatorTest.java
deleted file mode 100644
index adf86e2..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderComparatorTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- *  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.isis.core.runtime.services;
-
-import java.util.*;
-import com.google.common.collect.Iterators;
-import org.apache.isis.commons.internal.collections._Lists;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import org.apache.isis.core.metamodel.util.DeweyOrderComparator;
-
-import static org.hamcrest.CoreMatchers.is;
-
-public class DeweyOrderComparatorTest {
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @Test
-    public void emptySet() throws Exception {
-        assertThatSorting(
-                ofS(),
-                ofL());
-    }
-
-    @Test
-    public void singleElement() throws Exception {
-        assertThatSorting(
-                ofS("1"),
-                ofL("1")
-        );
-    }
-
-    @Test
-    public void inOrder() throws Exception {
-        assertThatSorting(
-                ofS("1", "2"),
-                ofL("1", "2")
-        );
-    }
-
-    @Test
-    public void notInOrder() throws Exception {
-        assertThatSorting(
-                ofS("2", "1"),
-                ofL("1", "2")
-        );
-    }
-
-    @Test
-    public void notInOrderDepth2() throws Exception {
-        assertThatSorting(
-                ofS("1.2", "1.1"),
-                ofL("1.1", "1.2")
-        );
-    }
-
-    @Test
-    public void differentDepths() throws Exception {
-        assertThatSorting(
-                ofS("2", "1.3", "1.2", "1.2.2", "1.2.1", "1.1"),
-                ofL("1.1", "1.2", "1.2.1", "1.2.2", "1.3", "2")
-        );
-    }
-
-    @Test
-    public void mismatchedDepth3() throws Exception {
-        assertThatSorting(
-                ofS("1.2.2", "1.2.1", "1.1"),
-                ofL("1.1", "1.2.1", "1.2.2")
-        );
-    }
-
-    @Test
-    public void X() throws Exception {
-        assertThatSorting(
-                ofS("45.1", "10.10"),
-                ofL("10.10", "45.1")
-        );
-    }
-
-    private static Collection<String> ofS(String... str) {
-        return Arrays.asList(str);
-    }
-
-    private static List<String> ofL(String... str) {
-        return _Lists.newArrayList(ofS(str));
-    }
-
-    private static void assertThatSorting(Collection<String> input, List<String> expected) {
-        final SortedSet<String> treeSet = new TreeSet<String>(new DeweyOrderComparator());
-        treeSet.addAll(input);
-        final List<String> strings = Arrays.asList(Iterators.toArray(treeSet.iterator(), String.class));
-        Assert.assertThat(strings, is(expected));
-    }
-
-}
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtil.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtil.java
deleted file mode 100644
index 092aab4..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtil.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- *  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.isis.core.runtime.services;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
-import org.apache.isis.commons.internal.collections._Sets;
-
-class DeweyOrderUtil  {
-
-    public static final <V> Function<Parsed, Map.Entry<String, V>> toMapEntry() {
-        return new Function<Parsed, Map.Entry<String, V>>() {
-            @Override
-            public Map.Entry<String, V> apply(Parsed input) {
-                return input.toMapEntry();
-            }
-        };
-    }
-
-    private DeweyOrderUtil() {}
-
-    static <V> List<Map.Entry<String, V>> deweySorted(Map<String, V> map) {
-        Set<Map.Entry<String, V>> set = _Sets.newLinkedHashSet();
-        for (Map.Entry<String, V> entry : map.entrySet()) {
-            set.add(entry);
-        }
-        return deweySorted(set);
-    }
-
-    static <V> List<Map.Entry<String, V>> deweySorted(Set<Map.Entry<String, V>> keys) {
-        if(keys == null) {
-            throw new IllegalArgumentException("Keys cannot be null");
-        }
-        final Iterable<Parsed<V>> parsedIter = Iterables.transform(keys,
-                new Function<Map.Entry<String,V>, Parsed<V>>() {
-            @Override
-            public Parsed<V> apply(Map.Entry<String,V> input) {
-                return new Parsed(input);
-            }
-        });
-
-        final SortedSet<Parsed<V>> parseds = _Sets.newTreeSet(parsedIter);
-        final Iterable<Map.Entry<String, V>> transform = Iterables.transform(parseds, DeweyOrderUtil.<V>toMapEntry());
-        return Lists.newArrayList(transform);
-    }
-
-}
-
-
-class Parsed<V> implements Comparable<Parsed<V>> {
-    private static final Function<String, Integer> PARSE = new Function<String, Integer>() {
-        @Override
-        public Integer apply(String input) {
-            try {
-                return Integer.parseInt(input);
-            } catch (NumberFormatException e) {
-                return Integer.MAX_VALUE;
-            }
-        }
-    };
-    private final List<Integer> parts;
-    private final String key;
-    private final V value;
-    Parsed(Map.Entry<String, V> entry) {
-        key = entry.getKey();
-        value = entry.getValue();
-        final Iterable<String> iter = Splitter.on(".").split(entry.getKey());
-        parts = Lists.newArrayList(Iterators.transform(iter.iterator(),PARSE));
-    }
-
-    @Override
-    public int compareTo(Parsed<V> other) {
-        for (int i = 0; i < parts.size(); i++) {
-            Integer p = parts.get(i);
-            if (other.parts.size() < parts.size()) {
-                // run out of parts for other, put it before us
-                return -1;
-            }
-            final Integer q = other.parts.get(i);
-            final int comparison = p.compareTo(q);
-            if(comparison != 0) {
-                return +comparison;
-            }
-        }
-        if(other.parts.size() > parts.size()) {
-            // run out of parts on our side, still more on others; put us before it
-            return +1;
-        }
-        return 0;
-    }
-
-    public Map.Entry<String, V> toMapEntry() {
-        return new MapEntry<String, V>(key, value){};
-    }
-}
-
-class MapEntry<K, V> implements Map.Entry<K, V> {
-
-    private K key;
-    private V value;
-
-    MapEntry(K key, V value) {
-        this.key = key;
-        this.value = value;
-    }
-
-    @Override
-    public K getKey() {
-        return key;
-    }
-
-    @Override
-    public V getValue() {
-        return value;
-    }
-
-    @Override
-    public V setValue(V value) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override public boolean equals(Object object) {
-        if (object instanceof Map.Entry) {
-            Map.Entry<?, ?> that = (Map.Entry<?, ?>) object;
-            return Objects.equal(this.getKey(), that.getKey())
-                    && Objects.equal(this.getValue(), that.getValue());
-        }
-        return false;
-    }
-
-    @Override public int hashCode() {
-        K k = getKey();
-        V v = getValue();
-        return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
-    }
-
-    /**
-     * Returns a string representation of the form {@code {key}={value}}.
-     */
-    @Override public String toString() {
-        return getKey() + "=" + getValue();
-    }
-}
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtilTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtilTest.java
deleted file mode 100644
index 5183d96..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/DeweyOrderUtilTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- *  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.isis.core.runtime.services;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.isis.commons.internal.collections._Lists;
-import org.apache.isis.commons.internal.collections._Sets;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.hamcrest.CoreMatchers.is;
-
-public class DeweyOrderUtilTest {
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @Test
-    public void emptySet() throws Exception {
-        assertThatSorting(
-                ofS(),
-                ofL());
-    }
-
-    @Test
-    public void singleElement() throws Exception {
-        assertThatSorting(
-                ofS(el("1", "aaa")),
-                ofL(el("1", "aaa")));
-    }
-
-    @Test
-    public void inOrder() throws Exception {
-        assertThatSorting(
-                ofS(el("1", "aaa"), el("2", "bbb")),
-                ofL(el("1", "aaa"), el("2", "bbb")));
-    }
-
-    @Test
-    public void notInOrder() throws Exception {
-        assertThatSorting(
-                ofS(el("2", "bbb"), el("1", "aaa")),
-                ofL(el("1", "aaa"), el("2", "bbb")));
-    }
-
-    @Test
-    public void notInOrderDepth2() throws Exception {
-        assertThatSorting(
-                ofS(el("1.2", "bbb"), el("1.1", "aaa")),
-                ofL(el("1.1", "aaa"), el("1.2", "bbb")));
-    }
-
-    @Test
-    public void differentDepths() throws Exception {
-        assertThatSorting(
-                ofS(el("2", "aaa"), el("1.3", "aaa"), el("1.2", "aaa"), el("1.2.2", "ccc"), el("1.2.1", "bbb"), el("1.1", "aaa")),
-                ofL(el("1.1", "aaa"), el("1.2.1", "bbb"), el("1.2.2", "ccc"), el("1.2", "aaa"), el("1.3", "aaa"), el("2", "aaa")));
-    }
-
-    @Test
-    public void mismatchedDepth3() throws Exception {
-        assertThatSorting(
-                ofS(el("1.2.2", "ccc"), el("1.2.1", "bbb"), el("1.1", "aaa")),
-                ofL(el("1.1", "aaa"), el("1.2.1", "bbb"), el("1.2.2", "ccc")));
-    }
-
-    private void assertThatSorting(Set<Map.Entry<String, Object>> input, List<Map.Entry<String, Object>> expected) {
-        final List<Map.Entry<String, Object>> list = DeweyOrderUtil.deweySorted(input);
-        Assert.assertThat(list, is(expected));
-    }
-
-
-    private static Set<Map.Entry<String, Object>> ofS(String[]... str) {
-        final Set<Map.Entry<String,Object>> seq = _Sets.newLinkedHashSet();
-        for (String[] strings : str) {
-            if(strings.length != 2) {
-                throw new IllegalArgumentException("array must have 2 elements");
-            }
-            seq.add(new MapEntry<String, Object>(strings[0], (Object) strings[1]));
-        }
-        return seq;
-    }
-
-    private static List<Map.Entry<String, Object>> ofL(String[]... str) {
-        return _Lists.newArrayList(ofS(str));
-    }
-
-
-    private static String[] el(String a, String b) {
-        return new String[]{a, b};
-    }
-
-}
\ No newline at end of file
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
index 4c53d0a..92ca5ec 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
@@ -32,7 +32,6 @@ import javax.enterprise.context.RequestScoped;
 
 import org.jmock.auto.Mock;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -66,13 +65,13 @@ public class ServiceInstantiatorTest {
 		assertThat(calculator.add(3,4), is(7));
 	}
 
-	@Test @Ignore("test is in core plugins codegen-*")
+	@Test
 	public void requestScoped_instantiate() {
 		AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
 		assertThat(calculator instanceof RequestScopedService, is(true));
 	}
 
-	@Test @Ignore("test is in core plugins codegen-*")
+	@Test
 	public void requestScoped_justOneThread() {
 		AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
 		try {
@@ -85,7 +84,7 @@ public class ServiceInstantiatorTest {
 		}
 	}
 
-	@Test @Ignore("test is in core plugins codegen-*")
+	@Test
 	public void requestScoped_multipleThreads() throws InterruptedException, BrokenBarrierException {
 
 		final AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
@@ -139,7 +138,7 @@ public class ServiceInstantiatorTest {
 		assertThat(totals[2], is(30));
 	}
 
-	@Test @Ignore("test is in core plugins codegen-*")
+	@Test
 	public void requestScoped_childThreads() throws InterruptedException  {
 
 		final Consumer consumer = serviceInstantiator.createInstance(Consumer.class);


[isis] 02/02: ISIS-1976: adding another test for RequestScope support

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git

commit e19af26777aff1c450f35b308ced2a1d8d99e246
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Sep 17 21:09:58 2018 +0200

    ISIS-1976: adding another test for RequestScope support
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
 .../core/metamodel/services/ServicesInjector.java  |  48 +++----
 .../services/ServicesInjectorDefaultTest.java      |  11 ++
 .../runtime/services/ServiceInstantiatorTest.java  |   9 +-
 .../ServiceInjectorTestUsingCodegenPlugin.java     | 153 +++++++++++++++++++++
 .../ServiceInstantiatorTestUsingCodegenPlugin.java |  11 +-
 5 files changed, 198 insertions(+), 34 deletions(-)

diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjector.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjector.java
index 89e8703..c47bf50 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjector.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjector.java
@@ -123,30 +123,30 @@ public class ServicesInjector implements ApplicationScopedComponent {
     }
 
     // -- REPLACE SERVICES
-
-    /**
-     * Update an individual service.
-     *
-     * <p>
-     * There should already be a service {@link #getRegisteredServices() registered} of the specified type.
-     *
-     * @return <tt>true</tt> if a service of the specified type was found and updated, <tt>false</tt> otherwise.
-     * @param existingService
-     * @param replacementService
-     */
-    public <T> void replaceService(final T existingService, final T replacementService) {
-
-        if(!services.remove(existingService)) {
-            throw new IllegalArgumentException("Service to be replaced was not found (" + existingService + ")");
-        }
-
-        services.add(replacementService);
-
-        // invalidate
-        servicesAssignableToType.clear();
-        serviceByConcreteType.clear();
-        autowire();
-    }
+//FIXME[ISIS-1976] not used
+//    /**
+//     * Update an individual service.
+//     *
+//     * <p>
+//     * There should already be a service {@link #getRegisteredServices() registered} of the specified type.
+//     *
+//     * @return <tt>true</tt> if a service of the specified type was found and updated, <tt>false</tt> otherwise.
+//     * @param existingService
+//     * @param replacementService
+//     */
+//    public <T> void replaceService(final T existingService, final T replacementService) {
+//
+//        if(!services.remove(existingService)) {
+//            throw new IllegalArgumentException("Service to be replaced was not found (" + existingService + ")");
+//        }
+//
+//        services.add(replacementService);
+//
+//        // invalidate
+//        servicesAssignableToType.clear();
+//        serviceByConcreteType.clear();
+//        autowire();
+//    }
 
     public boolean isRegisteredService(final Class<?> cls) {
         return serviceByConcreteType.get().containsKey(cls);
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefaultTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefaultTest.java
index 98d2493..694df53 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefaultTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefaultTest.java
@@ -20,12 +20,17 @@
 package org.apache.isis.core.metamodel.services;
 
 import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
 import org.jmock.Expectations;
 import org.jmock.auto.Mock;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+
 import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.core.commons.config.IsisConfigurationDefault;
 import org.apache.isis.core.metamodel.specloader.InjectorMethodEvaluatorDefault;
@@ -94,5 +99,11 @@ public class ServicesInjectorDefaultTest {
 
         injector.injectServicesInto(mockDomainObject);
     }
+    
+    @Test
+    public void shouldStreamRegisteredServices() {
+        List<Class<?>> registeredServices = injector.streamRegisteredServiceTypes().collect(Collectors.toList());
+        Assert.assertEquals(3, registeredServices.size());
+    }
 
 }
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
index 92ca5ec..d8d8897 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
@@ -32,6 +32,7 @@ import javax.enterprise.context.RequestScoped;
 
 import org.jmock.auto.Mock;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -65,13 +66,13 @@ public class ServiceInstantiatorTest {
 		assertThat(calculator.add(3,4), is(7));
 	}
 
-	@Test
+	@Test @Ignore("test is in core/unittestsupport-test")
 	public void requestScoped_instantiate() {
 		AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
 		assertThat(calculator instanceof RequestScopedService, is(true));
 	}
 
-	@Test
+	@Test @Ignore("test is in core/unittestsupport-test")
 	public void requestScoped_justOneThread() {
 		AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
 		try {
@@ -84,7 +85,7 @@ public class ServiceInstantiatorTest {
 		}
 	}
 
-	@Test
+	@Test @Ignore("test is in core/unittestsupport-test")
 	public void requestScoped_multipleThreads() throws InterruptedException, BrokenBarrierException {
 
 		final AccumulatingCalculator calculator = serviceInstantiator.createInstance(AccumulatingCalculator.class);
@@ -138,7 +139,7 @@ public class ServiceInstantiatorTest {
 		assertThat(totals[2], is(30));
 	}
 
-	@Test
+	@Test @Ignore("test is in core/unittestsupport-test")
 	public void requestScoped_childThreads() throws InterruptedException  {
 
 		final Consumer consumer = serviceInstantiator.createInstance(Consumer.class);
diff --git a/core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInjectorTestUsingCodegenPlugin.java b/core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInjectorTestUsingCodegenPlugin.java
new file mode 100644
index 0000000..c3cccd2
--- /dev/null
+++ b/core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInjectorTestUsingCodegenPlugin.java
@@ -0,0 +1,153 @@
+/*
+ *  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.isis.core.runtime.services;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import javax.enterprise.context.RequestScoped;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.commons.internal.collections._Lists;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+
+public class ServiceInjectorTestUsingCodegenPlugin {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(JUnitRuleMockery2.Mode.INTERFACES_AND_CLASSES);
+
+    private ServiceInstantiator serviceInstantiator;
+    private ServicesInjector serviceInjector;
+
+    @Before
+    public void setUp() throws Exception {
+
+        final IsisConfiguration configuration = new IsisConfigurationDefault();
+        
+        serviceInstantiator = new ServiceInstantiator();
+        serviceInstantiator.setConfiguration(configuration);
+        
+        final Object[] services = {
+                serviceInstantiator.createInstance(SingletonCalculator.class),
+                serviceInstantiator.createInstance(AccumulatingCalculator.class)
+                };
+        
+        serviceInjector = new ServicesInjector(_Lists.of(services), configuration);
+    }
+
+    @Test
+    public void singleton() {
+        SingletonCalculator calculator = serviceInjector.lookupService(SingletonCalculator.class);
+        assertThat(calculator.add(3), is(3));
+        calculator = serviceInjector.lookupService(SingletonCalculator.class);
+        assertThat(calculator.add(4), is(7));
+    }
+
+    @Test
+    public void requestScoped_instantiate() {
+        final AccumulatingCalculator calculator = serviceInjector.lookupService(AccumulatingCalculator.class);
+        assertThat(calculator instanceof RequestScopedService, is(true));
+    }
+
+    @Test
+    public void requestScoped_justOneThread() {
+        final AccumulatingCalculator calculator = serviceInjector.lookupService(AccumulatingCalculator.class);
+        
+        try {
+            ((RequestScopedService)calculator).__isis_startRequest(serviceInjector);
+            assertThat(calculator.add(3), is(3));
+            assertThat(calculator.add(4), is(7));
+            assertThat(calculator.getTotal(), is(7));
+        } finally {
+            ((RequestScopedService)calculator).__isis_endRequest();
+        }
+    }
+
+    @Test
+    public void requestScoped_multipleThreads() throws InterruptedException, ExecutionException {
+        
+        final AccumulatingCalculator calculator = serviceInjector.lookupService(AccumulatingCalculator.class);
+        final ExecutorService executor = Executors.newFixedThreadPool(10);
+        
+        // setup 32 tasks
+        final List<Callable<Integer>> tasks = IntStream.range(0, 32)
+        .<Callable<Integer>>mapToObj(index->()->{
+            
+            // within each task setup a new calculator instance that adds the numbers from 1 .. 100 = 5050
+            ((RequestScopedService)calculator).__isis_startRequest(serviceInjector);
+            for(int i=1; i<=100; i++) {
+                calculator.add(i);    
+            }
+            try {
+                return calculator.getTotal();
+            } finally {
+                ((RequestScopedService)calculator).__isis_endRequest();
+            }
+        })
+        .collect(Collectors.toList());
+        
+        
+        final List<Future<Integer>> results = executor.invokeAll(tasks);
+        executor.shutdown();
+        executor.awaitTermination(5, TimeUnit.SECONDS);
+
+        // we expect that each of the 32 calculators have calculated the sum correctly
+        for(Future<Integer> future: results) {
+            assertThat(future.get(), is(5050));
+        }
+    }
+
+    public static class SingletonCalculator {
+        private int total;
+        public int add(int x) {
+            total += x;
+            return getTotal();
+        }
+        public int getTotal() {
+            return total;
+        }
+    }
+
+    @RequestScoped
+    public static class AccumulatingCalculator {
+        private int total;
+        public int add(int x) {
+            total += x;
+            return getTotal();
+        }
+        public int getTotal() {
+            return total;
+        }
+    }
+
+}
diff --git a/core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTestUsingCodegenPlugin.java b/core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTestUsingCodegenPlugin.java
index 86fd8d2..c8e354c 100644
--- a/core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTestUsingCodegenPlugin.java
+++ b/core/unittestsupport-test/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTestUsingCodegenPlugin.java
@@ -1,5 +1,4 @@
-package org.apache.isis.core.runtime.services;
-/**
+/*
  *  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.
@@ -15,7 +14,11 @@ package org.apache.isis.core.runtime.services;
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
+package org.apache.isis.core.runtime.services;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 
 import java.util.Collections;
 import java.util.List;
@@ -40,10 +43,6 @@ import org.apache.isis.core.commons.config.IsisConfigurationDefault;
 import org.apache.isis.core.metamodel.services.ServicesInjector;
 import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
 public class ServiceInstantiatorTestUsingCodegenPlugin {
 
     @Rule