// Copyright 2017 The Nomulus Authors. All Rights Reserved. // // 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 google.registry.tools.server; import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import google.registry.model.OteStatsTestHelper; import google.registry.testing.AppEngineRule; import java.util.Map; import java.util.regex.Pattern; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Unit tests for {@link VerifyOteAction}. */ @RunWith(JUnit4.class) public class VerifyOteActionTest { @Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); private final VerifyOteAction action = new VerifyOteAction(); @Before public void init() throws Exception { OteStatsTestHelper.setupHistoryEntries(); } @Test public void testSuccess_summarize_allPass() { assertThat(getResponse(true)) .isEqualTo("# actions: 31 - Reqs: [----------------] 16/16 - Overall: PASS"); } @Test public void testFailure_summarize_someFailures() { OteStatsTestHelper.deleteDomainCreateHistoryEntry(); OteStatsTestHelper.deleteDomainRestoreHistoryEntry(); OteStatsTestHelper.deleteHostDeleteHistoryEntry(); assertThat(getResponse(true)) .isEqualTo("# actions: 35 - Reqs: [-.-----.------.-] 13/16 - Overall: FAIL"); } @Test public void testSuccess_passNotSummarized() { String expectedOteStatus = "domain creates idn: 1\n" + "domain creates start date sunrise: 1\n" + "domain creates with claims notice: 1\n" + "domain creates with fee: 1\n" + "domain creates with sec dns: 1\n" + ".*" + "domain deletes: 2\n" + ".*" + "domain restores: 1\n" + "domain transfer approves: 1\n" + "domain transfer cancels: 1\n" + "domain transfer rejects: 1\n" + "domain transfer requests: 1\n" + ".*" + "domain updates with sec dns: 1\n" + ".*" + "host creates subordinate: 1\n" + "host deletes: 1\n" + "host updates: 1\n" + ".*" + "Requirements passed: 16/16\n" + "Overall OT&E status: PASS\n"; Pattern expectedOteStatusPattern = Pattern.compile(expectedOteStatus, Pattern.DOTALL); assertThat(getResponse(false)).containsMatch(expectedOteStatusPattern); } @Test public void testFailure_missingHostDelete() { OteStatsTestHelper.deleteHostDeleteHistoryEntry(); String expectedOteStatus = "domain creates idn: 1\n" + "domain creates start date sunrise: 1\n" + "domain creates with claims notice: 1\n" + "domain creates with fee: 1\n" + "domain creates with sec dns: 1\n" + ".*" + "domain deletes: 2\n" + ".*" + "domain restores: 1\n" + "domain transfer approves: 1\n" + "domain transfer cancels: 1\n" + "domain transfer rejects: 1\n" + "domain transfer requests: 1\n" + ".*" + "domain updates with sec dns: 1\n" + ".*" + "host creates subordinate: 1\n" + "host deletes: 0\n" + "host updates: 10\n" + ".*" + "Requirements passed: 15/16\n" + "Overall OT&E status: FAIL\n"; Pattern expectedOteStatusPattern = Pattern.compile(expectedOteStatus, Pattern.DOTALL); assertThat(getResponse(false)).containsMatch(expectedOteStatusPattern); } private String getResponse(boolean summarize) { Map response = action.handleJsonRequest( ImmutableMap.of( "summarize", Boolean.toString(summarize), "registrars", ImmutableList.of("blobio"))); assertThat(response).containsKey("blobio"); return response.get("blobio").toString(); } }