summaryrefslogtreecommitdiff
path: root/src/test/java/com/android/vts/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/android/vts/api')
-rw-r--r--src/test/java/com/android/vts/api/CoverageRestServletTest.java112
-rw-r--r--src/test/java/com/android/vts/api/DataRestServletTest.java143
-rw-r--r--src/test/java/com/android/vts/api/VtsSpreadSheetSyncServletTest.java131
3 files changed, 0 insertions, 386 deletions
diff --git a/src/test/java/com/android/vts/api/CoverageRestServletTest.java b/src/test/java/com/android/vts/api/CoverageRestServletTest.java
deleted file mode 100644
index f900f79..0000000
--- a/src/test/java/com/android/vts/api/CoverageRestServletTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2018 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.vts.api;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
-import static com.googlecode.objectify.ObjectifyService.factory;
-
-import com.android.vts.entity.ApiCoverageEntity;
-import com.android.vts.entity.TestEntity;
-import com.android.vts.entity.TestRunEntity;
-import com.android.vts.util.ObjectifyTestBase;
-import com.google.gson.Gson;
-import com.google.gson.internal.LinkedTreeMap;
-import com.googlecode.objectify.Key;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import java.util.Arrays;
-import java.util.List;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.BeforeEach;
-import org.mockito.Mock;
-
-public class CoverageRestServletTest extends ObjectifyTestBase {
-
- private Gson gson;
-
- @Mock
- private HttpServletRequest request;
-
- @Mock
- private HttpServletResponse response;
-
- /** It be executed before each @Test method */
- @BeforeEach
- void setUpExtra() {
- gson = new Gson();
-
- /********
- System.getenv().forEach((k,v) -> {
- System.out.println("key => " + k);
- System.out.println("value => " + v);
- });
- *********/
- }
-
- @Test
- public void testApiData() throws IOException, ServletException {
-
- factory().register(ApiCoverageEntity.class);
-
- List<String> halApi = Arrays.asList("allocate", "dumpDebugInfo");
- List<String> coveredHalApi = Arrays.asList("allocate", "dumpDebugInfo");
-
- Key testParentKey = Key.create(TestEntity.class, "test1");
- Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1);
- ApiCoverageEntity apiCoverageEntity =
- new ApiCoverageEntity(
- testRunParentKey,
- "android.hardware.graphics.allocator",
- 4,
- 1,
- "IAllocator",
- halApi,
- coveredHalApi);
- apiCoverageEntity.save();
-
- String key = apiCoverageEntity.getUrlSafeKey();
-
- when(request.getPathInfo()).thenReturn("/api/data");
-
- when(request.getParameter("key")).thenReturn(key);
-
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
-
- when(response.getWriter()).thenReturn(pw);
-
- CoverageRestServlet coverageRestServlet = new CoverageRestServlet();
- coverageRestServlet.doGet(request, response);
- String result = sw.getBuffer().toString().trim();
-
- LinkedTreeMap resultMap = gson.fromJson(result, LinkedTreeMap.class);
-
- assertEquals(resultMap.get("halInterfaceName"), "IAllocator");
- assertEquals(resultMap.get("halPackageName"), "android.hardware.graphics.allocator");
- assertEquals(resultMap.get("halApi"), Arrays.asList("allocate", "dumpDebugInfo"));
- assertEquals(resultMap.get("coveredHalApi"), Arrays.asList("allocate", "dumpDebugInfo"));
-
- }
-
-}
diff --git a/src/test/java/com/android/vts/api/DataRestServletTest.java b/src/test/java/com/android/vts/api/DataRestServletTest.java
deleted file mode 100644
index b01c761..0000000
--- a/src/test/java/com/android/vts/api/DataRestServletTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2018 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.vts.api;
-
-import com.android.vts.entity.BranchEntity;
-import com.android.vts.entity.BuildTargetEntity;
-import com.android.vts.entity.DeviceInfoEntity;
-import com.android.vts.entity.TestEntity;
-import com.android.vts.entity.TestRunEntity;
-import com.android.vts.util.ObjectifyTestBase;
-import com.google.gson.Gson;
-import com.googlecode.objectify.Key;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mock;
-import org.mockito.Spy;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.LinkedList;
-
-import static com.googlecode.objectify.ObjectifyService.factory;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
-
-public class DataRestServletTest extends ObjectifyTestBase {
-
- private Gson gson;
-
- @Spy private DataRestServlet servlet;
-
- @Mock private HttpServletRequest request;
-
- @Mock private HttpServletResponse response;
-
- /** It be executed before each @Test method */
- @BeforeEach
- void setUpExtra() {
- gson = new Gson();
-
- factory().register(TestEntity.class);
- factory().register(TestRunEntity.class);
- factory().register(BranchEntity.class);
- factory().register(BuildTargetEntity.class);
- factory().register(DeviceInfoEntity.class);
-
- BranchEntity branchEntity1 = new BranchEntity("master");
- branchEntity1.save();
- BranchEntity branchEntity2 = new BranchEntity("pi");
- branchEntity2.save();
-
- BuildTargetEntity buildTargetEntity1 = new BuildTargetEntity("aosp_arm64_ab-userdebug");
- buildTargetEntity1.save();
- BuildTargetEntity buildTargetEntity2 = new BuildTargetEntity("sailfish-userdebug");
- buildTargetEntity2.save();
-
- Key testParentKey = Key.create(TestEntity.class, "test1");
- Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1);
- DeviceInfoEntity deviceInfoEntity1 =
- new DeviceInfoEntity(
- testRunParentKey,
- "pi",
- "sailfish",
- "sailfish-userdebug",
- "4585723",
- "64",
- "arm64-v8a");
- deviceInfoEntity1.setId(2384723984L);
- deviceInfoEntity1.save();
-
- DeviceInfoEntity deviceInfoEntity2 =
- new DeviceInfoEntity(
- testRunParentKey,
- "master",
- "walleye",
- "aosp_arm64_ab-userdebug",
- "4585723",
- "64",
- "arm64-v8a");
- deviceInfoEntity2.setId(2384723422L);
- deviceInfoEntity2.save();
- }
-
- @Test
- public void testBranchData() throws IOException, ServletException {
-
- when(request.getPathInfo()).thenReturn("/branch");
- when(request.getParameter("schKey")).thenReturn("*");
-
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
-
- when(response.getWriter()).thenReturn(pw);
-
- servlet.doGet(request, response);
- String result = sw.getBuffer().toString().trim();
-
- LinkedList resultList = gson.fromJson(result, LinkedList.class);
-
- assertEquals(resultList.size(), 2);
- assertEquals(resultList.get(0), "master");
- assertEquals(resultList.get(1), "pi");
- }
-
- @Test
- public void testDeviceData() throws IOException, ServletException {
-
- when(request.getPathInfo()).thenReturn("/device");
- when(request.getParameter("schKey")).thenReturn("*");
-
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
-
- when(response.getWriter()).thenReturn(pw);
-
- servlet.doGet(request, response);
- String result = sw.getBuffer().toString().trim();
-
- LinkedList resultList = gson.fromJson(result, LinkedList.class);
-
- assertEquals(resultList.size(), 2);
- assertEquals(resultList.get(0), "aosp_arm64_ab-userdebug");
- assertEquals(resultList.get(1), "sailfish-userdebug");
- }
-}
diff --git a/src/test/java/com/android/vts/api/VtsSpreadSheetSyncServletTest.java b/src/test/java/com/android/vts/api/VtsSpreadSheetSyncServletTest.java
deleted file mode 100644
index 661ea9e..0000000
--- a/src/test/java/com/android/vts/api/VtsSpreadSheetSyncServletTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (C) 2018 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.vts.api;
-
-import com.android.vts.entity.ApiCoverageExcludedEntity;
-import com.android.vts.job.VtsSpreadSheetSyncServlet;
-import com.android.vts.util.ObjectifyTestBase;
-import com.google.api.client.extensions.appengine.datastore.AppEngineDataStoreFactory;
-import com.google.api.services.sheets.v4.SheetsScopes;
-import com.google.gson.Gson;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mock;
-import org.mockito.Spy;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import static com.googlecode.objectify.ObjectifyService.factory;
-import static com.googlecode.objectify.ObjectifyService.ofy;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
-
-@Slf4j
-public class VtsSpreadSheetSyncServletTest extends ObjectifyTestBase {
-
- private Gson gson;
-
- @Spy private VtsSpreadSheetSyncServlet servlet;
-
- @Mock private HttpServletRequest request;
-
- @Mock private HttpServletResponse response;
-
- @Mock private ServletContext context;
-
- @Mock private ServletConfig servletConfig;
-
- @Mock private ServletOutputStream outputStream;
-
- private final AppEngineDataStoreFactory DATA_STORE_FACTORY = new AppEngineDataStoreFactory();
-
- private final List<String> GOOGLE_API_SCOPES =
- Collections.singletonList(SheetsScopes.SPREADSHEETS_READONLY);
-
- /** It be executed before each @Test method */
- @BeforeEach
- void setUpExtra() {
-
- factory().register(ApiCoverageExcludedEntity.class);
-
- gson = new Gson();
-
- Properties systemConfigProp = new Properties();
-
- InputStream defaultInputStream =
- VtsSpreadSheetSyncServletTest.class
- .getClassLoader()
- .getResourceAsStream("config.properties");
-
- try {
- systemConfigProp.load(defaultInputStream);
- } catch (FileNotFoundException e) {
- log.error(e.getMessage());
- } catch (IOException e) {
- log.error(e.getMessage());
- }
-
- when(request.getServletContext()).thenReturn(context);
- when(request.getServletContext().getAttribute("dataStoreFactory"))
- .thenReturn(DATA_STORE_FACTORY);
- when(request.getServletContext().getAttribute("googleApiScopes"))
- .thenReturn(GOOGLE_API_SCOPES);
-
- when(servletConfig.getServletContext()).thenReturn(context);
- when(servletConfig.getServletContext().getAttribute("systemConfigProp"))
- .thenReturn(systemConfigProp);
-
- }
-
- @Test
- public void testSyncServletJob() throws IOException, ServletException {
-
- when(request.getPathInfo()).thenReturn("/cron/vts_spreadsheet_sync_job");
-
- when(servlet.getServletConfig()).thenReturn(servletConfig);
- when(response.getOutputStream()).thenReturn(outputStream);
-
- servlet.init(servletConfig);
- servlet.doGet(request, response);
- String result = outputStream.toString().trim();
-
- List<ApiCoverageExcludedEntity> apiCoverageExcludedEntityList =
- ofy().load().type(ApiCoverageExcludedEntity.class).list();
-
- assertEquals(apiCoverageExcludedEntityList.size(), 2);
- assertEquals(apiCoverageExcludedEntityList.get(0).getApiName(), "getMasterMuteTest");
- assertEquals(
- apiCoverageExcludedEntityList.get(0).getPackageName(),
- "android.hardware.audio.test");
- assertEquals(apiCoverageExcludedEntityList.get(1).getApiName(), "getMasterVolumeTest");
- assertEquals(
- apiCoverageExcludedEntityList.get(1).getPackageName(),
- "android.hardware.video.test");
- }
-}