1 /* 2 * Copyright 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.adservices.ondevicepersonalization; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.ComponentName; 22 import android.os.PersistableBundle; 23 24 import org.junit.Test; 25 26 public class ExecuteInIsolatedServiceRequestTest { 27 private static final ComponentName COMPONENT_NAME = 28 ComponentName.createRelative("com.example.service", ".Example"); 29 30 @Test buildRequestWithOption_success()31 public void buildRequestWithOption_success() { 32 PersistableBundle bundle = new PersistableBundle(); 33 bundle.putString("key", "ok"); 34 35 ExecuteInIsolatedServiceRequest request = 36 new ExecuteInIsolatedServiceRequest.Builder(COMPONENT_NAME) 37 .setAppParams(bundle) 38 .setOutputSpec( 39 ExecuteInIsolatedServiceRequest.OutputSpec.buildBestValueSpec(100)) 40 .build(); 41 42 ExecuteInIsolatedServiceRequest.OutputSpec options = request.getOutputSpec(); 43 assertThat(options.getMaxIntValue()).isEqualTo(100); 44 assertThat(options.getOutputType()) 45 .isEqualTo(ExecuteInIsolatedServiceRequest.OutputSpec.OUTPUT_TYPE_BEST_VALUE); 46 assertThat(request.getAppParams()).isEqualTo(bundle); 47 assertThat(request.getService()).isEqualTo(COMPONENT_NAME); 48 } 49 50 @Test buildRequestWithoutOption_success()51 public void buildRequestWithoutOption_success() { 52 PersistableBundle bundle = new PersistableBundle(); 53 bundle.putString("key", "ok"); 54 55 ExecuteInIsolatedServiceRequest request = 56 new ExecuteInIsolatedServiceRequest.Builder(COMPONENT_NAME) 57 .setAppParams(bundle) 58 .build(); 59 60 ExecuteInIsolatedServiceRequest.OutputSpec options = request.getOutputSpec(); 61 assertThat(options).isEqualTo(ExecuteInIsolatedServiceRequest.OutputSpec.DEFAULT); 62 assertThat(request.getAppParams()).isEqualTo(bundle); 63 assertThat(request.getService()).isEqualTo(COMPONENT_NAME); 64 } 65 66 @Test buildRequest_noParams_success()67 public void buildRequest_noParams_success() { 68 ExecuteInIsolatedServiceRequest request = 69 new ExecuteInIsolatedServiceRequest.Builder(COMPONENT_NAME).build(); 70 71 assertThat(request.getService()).isEqualTo(COMPONENT_NAME); 72 } 73 } 74