|
| 1 | +/* |
| 2 | + * Copyright 2020 EPAM Systems |
| 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 com.epam.reportportal.junit.attribute; |
| 18 | + |
| 19 | +import com.epam.reportportal.junit.ReportPortalListener; |
| 20 | +import com.epam.reportportal.junit.features.attribute.ClassLevelKeyValueAttributeTest; |
| 21 | +import com.epam.reportportal.junit.utils.TestUtils; |
| 22 | +import com.epam.reportportal.service.ReportPortal; |
| 23 | +import com.epam.reportportal.service.ReportPortalClient; |
| 24 | +import com.epam.reportportal.util.test.CommonUtils; |
| 25 | +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; |
| 26 | +import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; |
| 27 | +import org.junit.jupiter.api.BeforeEach; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import org.mockito.ArgumentCaptor; |
| 30 | +import org.mockito.ArgumentMatchers; |
| 31 | + |
| 32 | +import static com.epam.reportportal.junit.utils.TestUtils.PROCESSING_TIMEOUT; |
| 33 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 34 | +import static org.hamcrest.Matchers.*; |
| 35 | +import static org.mockito.Mockito.*; |
| 36 | + |
| 37 | +public class ClassKvAttributeTest { |
| 38 | + |
| 39 | + private final String classId = CommonUtils.namedId("class_"); |
| 40 | + private final String methodId = CommonUtils.namedId("method_"); |
| 41 | + |
| 42 | + private final ReportPortalClient client = mock(ReportPortalClient.class); |
| 43 | + |
| 44 | + @BeforeEach |
| 45 | + public void setupMock() { |
| 46 | + TestUtils.mockLaunch(client, null, null, classId, methodId); |
| 47 | + TestUtils.mockBatchLogging(client); |
| 48 | + ReportPortalListener.setReportPortal(ReportPortal.create(client, TestUtils.standardParameters(), TestUtils.testExecutor())); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void verify_static_attribute_bypass() { |
| 53 | + TestUtils.runClasses(ClassLevelKeyValueAttributeTest.class); |
| 54 | + |
| 55 | + ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); |
| 56 | + verify(client, timeout(PROCESSING_TIMEOUT)).startTestItem( |
| 57 | + ArgumentMatchers.startsWith(TestUtils.ROOT_SUITE_PREFIX), |
| 58 | + captor.capture() |
| 59 | + ); |
| 60 | + |
| 61 | + StartTestItemRQ suiteRq = captor.getValue(); |
| 62 | + assertThat(suiteRq.getAttributes(), allOf(notNullValue(), hasSize(1))); |
| 63 | + ItemAttributesRQ attribute = suiteRq.getAttributes().iterator().next(); |
| 64 | + assertThat(attribute.getKey(), equalTo(ClassLevelKeyValueAttributeTest.KEY)); |
| 65 | + assertThat(attribute.getValue(), equalTo(ClassLevelKeyValueAttributeTest.VALUE)); |
| 66 | + |
| 67 | + captor = ArgumentCaptor.forClass(StartTestItemRQ.class); |
| 68 | + verify(client, timeout(PROCESSING_TIMEOUT)).startTestItem(same(classId), captor.capture()); |
| 69 | + StartTestItemRQ testRq = captor.getValue(); |
| 70 | + assertThat(testRq.getAttributes(), anyOf(nullValue(), emptyIterable())); |
| 71 | + } |
| 72 | +} |
0 commit comments