You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/06/11 12:31:25 UTC

[isis] 02/08: ISIS-2732: deletes TickingFixtureClock, ClockFixture, TickingClockFixture

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

danhaywood pushed a commit to branch ISIS-2732
in repository https://gitbox.apache.org/repos/asf/isis.git

commit ee03db1669689619fcc666d2eac3bfacc0d21c5e
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jun 11 11:53:22 2021 +0100

    ISIS-2732: deletes TickingFixtureClock, ClockFixture, TickingClockFixture
---
 .../2018/2.0.0-M1/mignotes/legacy-modules.adoc     |   4 +-
 .../fixtures/applib/clock/ClockFixture.java        | 126 --------------
 .../fixtures/applib/clock/TickingClockFixture.java | 142 ----------------
 .../applib/clock/clock/TickingFixtureClock.java    | 184 ---------------------
 4 files changed, 2 insertions(+), 454 deletions(-)

diff --git a/antora/components/relnotes/modules/ROOT/pages/2018/2.0.0-M1/mignotes/legacy-modules.adoc b/antora/components/relnotes/modules/ROOT/pages/2018/2.0.0-M1/mignotes/legacy-modules.adoc
index b4737e0..120f955 100644
--- a/antora/components/relnotes/modules/ROOT/pages/2018/2.0.0-M1/mignotes/legacy-modules.adoc
+++ b/antora/components/relnotes/modules/ROOT/pages/2018/2.0.0-M1/mignotes/legacy-modules.adoc
@@ -59,11 +59,11 @@ fixtures`
 
 
 |`DateFixture`
-|Use `TickingClockFixture` instead
+|Use `SudoService` instead
 
 
 |`SwitchUserFixture`
-|Use fixture with injected `SudoService` instead
+|Use `SudoService` instead
 
 
 .2+|o.a.i.applib.
diff --git a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/ClockFixture.java b/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/ClockFixture.java
deleted file mode 100644
index 419b481..0000000
--- a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/ClockFixture.java
+++ /dev/null
@@ -1,126 +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.testing.fixtures.applib.clock;
-
-import org.joda.time.LocalDate;
-import org.joda.time.LocalDateTime;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
-
-import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.testing.fixtures.applib.fixturescripts.FixtureScriptWithExecutionStrategy;
-import org.apache.isis.testing.fixtures.applib.fixturescripts.FixtureScript;
-import org.apache.isis.testing.fixtures.applib.fixturescripts.FixtureScripts;
-import org.apache.isis.testing.fixtures.applib.clock.clock.Clock;
-import org.apache.isis.testing.fixtures.applib.clock.clock.FixtureClock;
-
-@Programmatic
-class ClockFixture extends FixtureScript implements FixtureScriptWithExecutionStrategy {
-
-    static ClockFixture setTo(final String date) {
-        return new ClockFixture().setDate(date);
-    }
-
-    ClockFixture() {
-        super(null, "clock");
-    }
-
-    private String date;
-
-    public String getDate() {
-        return date;
-    }
-
-    public ClockFixture setDate(final String date) {
-        this.date = date;
-        return this;
-    }
-
-    @Override
-    protected void execute(ExecutionContext ec) {
-
-        // can only be used in the context of integration tests
-        if (!(Clock.getInstance() instanceof FixtureClock)) {
-            throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
-        }
-        final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();
-
-        // check that some value has been set
-        checkParam("date", ec, String.class);
-
-        // process if can be parsed as a LocalDateTime
-        LocalDateTime ldt = parseAsLocalDateTime(date);
-        if (ldt != null) {
-            fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
-            fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
-            return;
-        }
-
-        // else process if can be parsed as a LocalDate
-        LocalDate ld = parseAsLocalDate(date);
-        if (ld != null) {
-            fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
-            return;
-        }
-
-        // else
-        throw new IllegalArgumentException(String.format(
-                "'%s' could not be parsed as a local date/time or local date", date));
-    }
-
-    private static LocalDate parseAsLocalDate(String dateStr) {
-        for (DateTimeFormatter formatter : new DateTimeFormatter[] {
-                DateTimeFormat.fullDateTime(),
-                DateTimeFormat.mediumDateTime(),
-                DateTimeFormat.shortDateTime(),
-                DateTimeFormat.forPattern("yyyy-MM-dd"),
-                DateTimeFormat.forPattern("yyyyMMdd"),
-        }) {
-            try {
-                return formatter.parseLocalDate(dateStr);
-            } catch (Exception e) {
-                // continue;
-            }
-        }
-        return null;
-    }
-
-    private static LocalDateTime parseAsLocalDateTime(String dateStr) {
-        for (DateTimeFormatter formatter : new DateTimeFormatter[] {
-                DateTimeFormat.fullDateTime(),
-                DateTimeFormat.mediumDateTime(),
-                DateTimeFormat.shortDateTime(),
-                DateTimeFormat.forPattern("yyyyMMddhhmmss"),
-                DateTimeFormat.forPattern("yyyyMMddhhmm")
-        }) {
-            try {
-                return formatter.parseLocalDateTime(dateStr);
-            } catch (Exception e) {
-                // continue;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public FixtureScripts.MultipleExecutionStrategy getMultipleExecutionStrategy() {
-        return FixtureScripts.MultipleExecutionStrategy.EXECUTE;
-    }
-
-}
diff --git a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/TickingClockFixture.java b/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/TickingClockFixture.java
deleted file mode 100644
index 80991af..0000000
--- a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/TickingClockFixture.java
+++ /dev/null
@@ -1,142 +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.testing.fixtures.applib.clock;
-
-import org.joda.time.LocalDate;
-import org.joda.time.LocalDateTime;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
-
-import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.testing.fixtures.applib.fixturescripts.FixtureScriptWithExecutionStrategy;
-import org.apache.isis.testing.fixtures.applib.fixturescripts.FixtureScript;
-import org.apache.isis.testing.fixtures.applib.fixturescripts.FixtureScripts;
-import org.apache.isis.testing.fixtures.applib.clock.clock.Clock;
-import org.apache.isis.testing.fixtures.applib.clock.clock.FixtureClock;
-import org.apache.isis.testing.fixtures.applib.clock.clock.TickingFixtureClock;
-
-/**
- * @since 2.x {@index}
- */
-@Programmatic
-public class TickingClockFixture
-extends FixtureScript
-implements FixtureScriptWithExecutionStrategy {
-
-    // -- date property
-    private String date;
-    public String getDate() {
-        return date;
-    }
-    public TickingClockFixture setDate(final String date) {
-        this.date = date;
-        return this;
-    }
-
-
-    @Override
-    protected void execute(ExecutionContext ec) {
-
-        // check that some value has been set
-        checkParam("date", ec, String.class);
-
-        final Clock instance = Clock.getInstance();
-
-        if(instance instanceof TickingFixtureClock) {
-            try {
-                TickingFixtureClock.reinstateExisting();
-                setTo(date);
-            } finally {
-                TickingFixtureClock.replaceExisting();
-            }
-        }
-
-        if(instance instanceof FixtureClock) {
-            setTo(date);
-        }
-    }
-
-    private void setTo(final String date) {
-
-        if (!(Clock.getInstance() instanceof FixtureClock)) {
-            throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
-        }
-        final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();
-
-        // process if can be parsed as a LocalDateTime
-        LocalDateTime ldt = parseAsLocalDateTime(date);
-        if (ldt != null) {
-            fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
-            fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
-            return;
-        }
-
-        // else process if can be parsed as a LocalDate
-        LocalDate ld = parseAsLocalDate(date);
-        if (ld != null) {
-            fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
-            return;
-        }
-
-        // else
-        throw new IllegalArgumentException(String.format(
-                "'%s' could not be parsed as a local date/time or local date", date));
-
-    }
-
-    private static LocalDate parseAsLocalDate(String dateStr) {
-        for (DateTimeFormatter formatter : new DateTimeFormatter[] {
-                DateTimeFormat.fullDateTime(),
-                DateTimeFormat.mediumDateTime(),
-                DateTimeFormat.shortDateTime(),
-                DateTimeFormat.forPattern("yyyy-MM-dd"),
-                DateTimeFormat.forPattern("yyyyMMdd"),
-        }) {
-            try {
-                return formatter.parseLocalDate(dateStr);
-            } catch (Exception e) {
-                // continue;
-            }
-        }
-        return null;
-    }
-
-    private static LocalDateTime parseAsLocalDateTime(String dateStr) {
-        for (DateTimeFormatter formatter : new DateTimeFormatter[] {
-                DateTimeFormat.fullDateTime(),
-                DateTimeFormat.mediumDateTime(),
-                DateTimeFormat.shortDateTime(),
-                DateTimeFormat.forPattern("yyyyMMddhhmmss"),
-                DateTimeFormat.forPattern("yyyyMMddhhmm")
-        }) {
-            try {
-                return formatter.parseLocalDateTime(dateStr);
-            } catch (Exception e) {
-                // continue;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public FixtureScripts.MultipleExecutionStrategy getMultipleExecutionStrategy() {
-        return FixtureScripts.MultipleExecutionStrategy.EXECUTE;
-    }
-
-}
diff --git a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/clock/TickingFixtureClock.java b/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/clock/TickingFixtureClock.java
deleted file mode 100644
index 6e8100d..0000000
--- a/testing/fixtures/applib/src/main/java/org/apache/isis/testing/fixtures/applib/clock/clock/TickingFixtureClock.java
+++ /dev/null
@@ -1,184 +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.testing.fixtures.applib.clock.clock;
-
-import java.sql.Timestamp;
-import java.time.Instant;
-import java.util.Calendar;
-import java.util.TimeZone;
-
-/**
- * @since 2.x {@index}
- */
-public class TickingFixtureClock extends Clock {
-    private static final TimeZone UTC_TIME_ZONE;
-
-    static {
-        TimeZone tempTimeZone = TimeZone.getTimeZone("Etc/UTC");
-        if (tempTimeZone == null) {
-            tempTimeZone = TimeZone.getTimeZone("UTC");
-        }
-        UTC_TIME_ZONE = tempTimeZone;
-    }
-
-
-    static Clock existingInstance;
-
-    /**
-     * Configures the system to use a FixtureClock rather than the in-built
-     * system clock. Can be called multiple times.
-     *
-     * <p>
-     * Must call before any other call to {@link Clock#getInstance()}.
-     *
-     * @throws IllegalStateException
-     *             if Clock singleton already initialized with some other
-     *             implementation.
-     */
-    public synchronized static TickingFixtureClock replaceExisting() {
-        final Clock instance = getInstance();
-        if (instance instanceof TickingFixtureClock) {
-            return (TickingFixtureClock) instance;
-        }
-
-        final long time = Clock.getEpochMillis();
-        existingInstance = Clock.instance;
-
-        // installs as the singleton
-        Clock.remove();
-
-        return new TickingFixtureClock(time);
-    }
-
-    /**
-     * Makes {@link Clock#remove()} visible.
-     */
-    public static boolean reinstateExisting() {
-        Clock.instance = existingInstance;
-        return true;
-    }
-
-
-
-    private final Calendar calendar = Calendar.getInstance();
-    private long t0 = 0L;
-
-    private TickingFixtureClock(final long time) {
-        calendar.setTimeZone(UTC_TIME_ZONE);
-        calendar.setTimeInMillis(time);
-
-        t0 = System.currentTimeMillis();
-    }
-
-    private long getOffset() {
-        return System.currentTimeMillis() - t0;
-    }
-
-
-    /**
-     * Access via {@link Clock#getTime()}.
-     *
-     * <p>
-     * Will just return the system time until {@link #setDate(int, int, int)} or
-     * {@link #setTime(int, int)} (or one of the overloads) has been called.
-     */
-    @Override
-    protected Instant now() {
-        return Instant.ofEpochMilli(calendar.getTime().getTime() + getOffset());
-    }
-
-    // //////////////////////////////////////////////////
-    // setting/adjusting time
-    // //////////////////////////////////////////////////
-
-    /**
-     * Sets the hours and minutes as specified, and sets the seconds and
-     * milliseconds to zero, but the date portion is left unchanged.
-     *
-     * @see #setDate(int, int, int)
-     * @see #addTime(int, int)
-     */
-    public void setTime(final int hour, final int min) {
-        calendar.set(Calendar.HOUR_OF_DAY, hour);
-        calendar.set(Calendar.MINUTE, min);
-        calendar.set(Calendar.SECOND, 0);
-        calendar.set(Calendar.MILLISECOND, 0);
-        t0 = System.currentTimeMillis();
-    }
-
-    public void setTime(final Timestamp timestamp) {
-        setTime(timestamp.getTime());
-    }
-
-    public void setTime(final long millis) {
-        calendar.setTimeInMillis(millis);
-        t0 = System.currentTimeMillis();
-    }
-
-    /**
-     * Sets the date, but the time portion is left unchanged.
-     *
-     * @see #setTime(int, int)
-     * @see #addDate(int, int, int)
-     */
-    public void setDate(final int year, final int month, final int day) {
-        calendar.set(Calendar.YEAR, year);
-        calendar.set(Calendar.MONTH, month - 1);
-        calendar.set(Calendar.DAY_OF_MONTH, day);
-
-        t0 = System.currentTimeMillis();
-    }
-
-    /**
-     * Adjusts the time by the specified number of hours and minutes.
-     *
-     * <p>
-     * Typically called after {@link #setTime(int, int)}, to move the clock
-     * forward or perhaps back.
-     *
-     * @see #addDate(int, int, int)
-     */
-    public void addTime(final int hours, final int minutes) {
-        calendar.add(Calendar.HOUR_OF_DAY, hours);
-        calendar.add(Calendar.MINUTE, minutes);
-    }
-
-    /**
-     * Adjusts the time by the specified number of years, months or days.
-     *
-     * <p>
-     * Typically called after {@link #setDate(int, int, int)}, to move the clock
-     * forward or perhaps back.
-     *
-     * @see #addTime(int, int)
-     */
-    public void addDate(final int years, final int months, final int days) {
-        calendar.add(Calendar.YEAR, years);
-        calendar.add(Calendar.MONTH, months);
-        calendar.add(Calendar.DAY_OF_MONTH, days);
-    }
-
-
-
-    @Override
-    public String toString() {
-        return Clock.getTimeAsOffsetDateTime().toString();
-    }
-
-}