1 /* 2 * Copyright (C) 2023 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.federatedcompute.common; 18 19 import static android.federatedcompute.common.TrainingInterval.SCHEDULING_MODE_ONE_TIME; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import static org.junit.Assert.assertThrows; 24 25 import androidx.test.ext.junit.runners.AndroidJUnit4; 26 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 30 @RunWith(AndroidJUnit4.class) 31 public final class ScheduleFederatedComputeRequestTest { 32 private static final String POPULATION_NAME = "population"; 33 private static final int JOB_ID = 1234; 34 35 @Test buildScheduleFederatedComputeRequest_success()36 public void buildScheduleFederatedComputeRequest_success() { 37 ScheduleFederatedComputeRequest request = 38 new ScheduleFederatedComputeRequest.Builder() 39 .setTrainingOptions( 40 new TrainingOptions.Builder() 41 .setPopulationName(POPULATION_NAME) 42 .setJobSchedulerJobId(JOB_ID) 43 .setTrainingInterval( 44 new TrainingInterval.Builder() 45 .setSchedulingMode(SCHEDULING_MODE_ONE_TIME) 46 .build()) 47 .build()) 48 .build(); 49 50 assertThat(request.getTrainingOptions().getJobSchedulerJobId()).isEqualTo(JOB_ID); 51 assertThat(request.getTrainingOptions().getPopulationName()).isEqualTo(POPULATION_NAME); 52 } 53 54 @Test testScheduleFederatedComputeRequestEquals()55 public void testScheduleFederatedComputeRequestEquals() { 56 ScheduleFederatedComputeRequest request1 = 57 new ScheduleFederatedComputeRequest.Builder() 58 .setTrainingOptions( 59 new TrainingOptions.Builder() 60 .setPopulationName(POPULATION_NAME) 61 .setJobSchedulerJobId(JOB_ID) 62 .setTrainingInterval( 63 new TrainingInterval.Builder() 64 .setSchedulingMode(SCHEDULING_MODE_ONE_TIME) 65 .build()) 66 .build()) 67 .build(); 68 ScheduleFederatedComputeRequest request2 = 69 new ScheduleFederatedComputeRequest.Builder() 70 .setTrainingOptions( 71 new TrainingOptions.Builder() 72 .setPopulationName(POPULATION_NAME) 73 .setJobSchedulerJobId(JOB_ID) 74 .setTrainingInterval( 75 new TrainingInterval.Builder() 76 .setSchedulingMode(SCHEDULING_MODE_ONE_TIME) 77 .build()) 78 .build()) 79 .build(); 80 81 assertThat(request1).isEqualTo(request2); 82 } 83 84 @Test buildNullTrainingOptions_failed()85 public void buildNullTrainingOptions_failed() { 86 assertThrows( 87 NullPointerException.class, 88 () -> new ScheduleFederatedComputeRequest.Builder().build()); 89 } 90 } 91