|
| 1 | +/* |
| 2 | + * Copyright 2022-2025 Google LLC |
| 3 | + * Copyright 2013-2021 CompilerWorks |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package com.google.edwmigration.dumper.application.dumper.connector.hadoop.oozie; |
| 18 | + |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | + |
| 21 | +import com.google.common.collect.ImmutableList; |
| 22 | +import java.text.SimpleDateFormat; |
| 23 | +import java.util.Date; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.junit.runners.JUnit4; |
| 27 | + |
| 28 | +@RunWith(JUnit4.class) |
| 29 | +public class AbstractOozieJobsTaskTest { |
| 30 | + |
| 31 | + static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| 32 | + |
| 33 | + @Test |
| 34 | + public void toRecordProperty_dateArgument_convertsToLong() throws Exception { |
| 35 | + Date christmas = dateFormat.parse("2025-12-25"); |
| 36 | + |
| 37 | + Object result = AbstractOozieJobsTask.toRecordProperty(christmas); |
| 38 | + |
| 39 | + assertEquals(Long.class, result.getClass()); |
| 40 | + assertEquals("2025-12-25", convertDate(result)); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void toRecordProperty_listArgument_success() throws Exception { |
| 45 | + ImmutableList<String> list = ImmutableList.of("abcde", "fghi"); |
| 46 | + |
| 47 | + Object result = AbstractOozieJobsTask.toRecordProperty(list); |
| 48 | + |
| 49 | + assertEquals("[\"abcde\",\"fghi\"]", result); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void toRecordProperty_otherArgument_nothingChanges() throws Exception { |
| 54 | + Object value = new Object(); |
| 55 | + |
| 56 | + Object result = AbstractOozieJobsTask.toRecordProperty(value); |
| 57 | + |
| 58 | + assertEquals(value, result); |
| 59 | + } |
| 60 | + |
| 61 | + private static String convertDate(Object date) { |
| 62 | + if (date instanceof Long) { |
| 63 | + return dateFormat.format(new Date((Long) date)); |
| 64 | + } |
| 65 | + throw new RuntimeException(); |
| 66 | + } |
| 67 | +} |
0 commit comments