summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-11-02 20:06:42 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-11-02 20:06:42 +0000
commite2e6b1b6a3fa883770aea506caca837d12780f30 (patch)
tree6a2b1904fc0d5a1417d8e19a8da780e67fb5980e
parentd0d23a6fa60eb2d052419afdd03c42fb54186f84 (diff)
parentb42335358e08900e1506139d04e059327f581222 (diff)
downloadcts-e2e6b1b6a3fa883770aea506caca837d12780f30.tar.gz
Merge "Snap for 7860912 from f46466abedc5bf37962cc58f6749c14f56f045c9 to pie-cts-release" into pie-cts-releaseandroid-cts-9.0_r18
-rw-r--r--common/device-side/util-axt/src/com/android/compatibility/common/util/ExtraBusinessLogicTestCase.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/common/device-side/util-axt/src/com/android/compatibility/common/util/ExtraBusinessLogicTestCase.java b/common/device-side/util-axt/src/com/android/compatibility/common/util/ExtraBusinessLogicTestCase.java
new file mode 100644
index 00000000000..c0a4eb97ed0
--- /dev/null
+++ b/common/device-side/util-axt/src/com/android/compatibility/common/util/ExtraBusinessLogicTestCase.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.android.compatibility.common.util;
+
+import android.util.Log;
+
+import com.android.compatibility.common.util.MultiLog;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+
+import java.util.List;
+
+/**
+ * Device-side base class for tests to run extra Business Logics in addition to the test-specific
+ * Business Logics.
+ *
+ * Used when running a common set of business logics against several tests.
+ *
+ * Usage:
+ * 1. Implement the common logic in an interface with default methods.
+ * 2. Extend this class and implement the interface.
+ *
+ * Now Business Logics rules and actions can be called from the GCL by using the interface fully
+ * qualified name.
+ */
+public abstract class ExtraBusinessLogicTestCase extends BusinessLogicTestCase implements MultiLog {
+
+ private static final String LOG_TAG = BusinessLogicTestCase.class.getSimpleName();
+
+ protected boolean mDependentOnBusinessLogic = true;
+
+ public abstract List<String> getExtraBusinessLogics();
+
+ @Before
+ @Override
+ public void handleBusinessLogic() {
+ loadBusinessLogic();
+ if (mDependentOnBusinessLogic) {
+ assertTrue(String.format(
+ "Test \"%s\" is unable to execute as it depends on the missing remote "
+ + "configuration.", mTestCase.getMethodName()), mCanReadBusinessLogic);
+ } else if (!mCanReadBusinessLogic) {
+ logInfo(LOG_TAG, "Skipping Business Logic for %s", mTestCase.getMethodName());
+ return;
+ }
+
+ BusinessLogicExecutor executor = new BusinessLogicDeviceExecutor(getContext(), this);
+ for (String extraBusinessLogic : getExtraBusinessLogics()) {
+ if (!mBusinessLogic.hasLogicFor(extraBusinessLogic)) {
+ throw new RuntimeException(String.format(
+ "can't find extra business logic for %s.", extraBusinessLogic));
+ }
+ mBusinessLogic.applyLogicFor(extraBusinessLogic, executor);
+ }
+ executeBusinessLogic();
+ }
+
+ // copied from MultiLogDevice because pi can't desugar the default methods
+ /** {@inheritDoc} */
+ @Override
+ public void logInfo(String logTag, String format, Object... args) {
+ Log.i(logTag, String.format(format, args));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void logDebug(String logTag, String format, Object... args) {
+ Log.d(logTag, String.format(format, args));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void logWarn(String logTag, String format, Object... args) {
+ Log.w(logTag, String.format(format, args));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void logError(String logTag, String format, Object... args) {
+ Log.e(logTag, String.format(format, args));
+ }
+}