From 7491f728474617c85b627ff0f0360ac5dd86ca88 Mon Sep 17 00:00:00 2001 From: Yingjian Wu Date: Fri, 8 Mar 2024 11:52:57 -0500 Subject: [PATCH 1/4] add test --- .../metacat/MySqlLookupServiceSpec.groovy | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy diff --git a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy new file mode 100644 index 000000000..689edf491 --- /dev/null +++ b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy @@ -0,0 +1,79 @@ +/* + * Copyright 2016 Netflix, Inc. + * + * 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 com.netflix.metacat + +import com.netflix.metacat.common.server.properties.DefaultConfigImpl +import com.netflix.metacat.common.server.properties.MetacatProperties +import com.netflix.metacat.metadata.mysql.MySqlLookupService +import org.springframework.jdbc.core.JdbcTemplate +import org.springframework.jdbc.datasource.DriverManagerDataSource +import spock.lang.Shared +import spock.lang.Specification + +class MySqlLookupServiceUnitTest extends Specification{ + private MySqlLookupService mySqlLookupService; + private JdbcTemplate jdbcTemplate; + + @Shared + MySqlLookupService mySqlLookupService + + @Shared + JdbcTemplate jdbcTemplate + + def setupSpec() { + String jdbcUrl = "jdbc:mysql://localhost:3306/metacat" + String username = "metacat_user" + String password = "metacat_user_password" + + DriverManagerDataSource dataSource = new DriverManagerDataSource() + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver") + dataSource.setUrl(jdbcUrl) + dataSource.setUsername(username) + dataSource.setPassword(password) + + jdbcTemplate = new JdbcTemplate(dataSource) + mySqlLookupService = new MySqlLookupService(new DefaultConfigImpl(new MetacatProperties()), jdbcTemplate) + // ... additional setup + } + + def "test get method"() { + when: + def lookup = mySqlLookupService.setValues("mock", ["1", "2", "3"] as Set) + then: + lookup.values.size() == 3 + when: + lookup = mySqlLookupService.setValues("mock", ["1", "2", "3", "4"] as Set) + then: + lookup.values.size() == 4 + when: + lookup = mySqlLookupService.setValues("mock", ["1", "2", "3", "3", "4"] as Set) + then: + lookup.values.size() == 4 + when: + lookup = mySqlLookupService.setValues("mock", ["3", "4"] as Set) + then: + lookup.values.size() == 2 + when: + lookup = mySqlLookupService.setValues("mock", ["6"] as Set) + then: + lookup.values.size() == 1 + when: + lookup = mySqlLookupService.setValues("mock", ["1", "6"] as Set) + then: + lookup.values.size() == 0 + } +} From 698a40bc1e692d64b7ef4d54673fc848c5c9e1a9 Mon Sep 17 00:00:00 2001 From: Yingjian Wu Date: Fri, 8 Mar 2024 12:01:02 -0500 Subject: [PATCH 2/4] add test --- .../metacat/MySqlLookupServiceSpec.groovy | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy index 689edf491..0091cc1fb 100644 --- a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy +++ b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy @@ -50,30 +50,22 @@ class MySqlLookupServiceUnitTest extends Specification{ // ... additional setup } - def "test get method"() { - when: - def lookup = mySqlLookupService.setValues("mock", ["1", "2", "3"] as Set) - then: - lookup.values.size() == 3 - when: - lookup = mySqlLookupService.setValues("mock", ["1", "2", "3", "4"] as Set) - then: - lookup.values.size() == 4 - when: - lookup = mySqlLookupService.setValues("mock", ["1", "2", "3", "3", "4"] as Set) - then: - lookup.values.size() == 4 - when: - lookup = mySqlLookupService.setValues("mock", ["3", "4"] as Set) - then: - lookup.values.size() == 2 - when: - lookup = mySqlLookupService.setValues("mock", ["6"] as Set) - then: - lookup.values.size() == 1 - when: - lookup = mySqlLookupService.setValues("mock", ["1", "6"] as Set) - then: - lookup.values.size() == 0 + def "test setValues iterative"() { + setup: + def values = valuesList as Set + def lookup = mySqlLookupService.setValues("mock", values) + + expect: + lookup.values.size() == expectedSize + lookup.values() == mySqlLookupService.getValues("mock") + + where: + valuesList | expectedSize + ["1", "2", "3"] | 3 + ["1", "2", "3", "4"] | 4 + ["1", "2", "3", "3", "4"] | 4 + ["3", "4"] | 2 + ["6"] | 1 + ["1", "6"] | 0 } } From 5aaed4bb068fa0517831220495ba5c3086961faf Mon Sep 17 00:00:00 2001 From: Yingjian Wu Date: Fri, 8 Mar 2024 12:01:56 -0500 Subject: [PATCH 3/4] add test --- .../groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy index 0091cc1fb..4eb68be97 100644 --- a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy +++ b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy @@ -24,7 +24,7 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource import spock.lang.Shared import spock.lang.Specification -class MySqlLookupServiceUnitTest extends Specification{ +class MySqlLookupServiceSpec extends Specification{ private MySqlLookupService mySqlLookupService; private JdbcTemplate jdbcTemplate; From bd2e127b8acd5324512fd87bb4e41908efdf7110 Mon Sep 17 00:00:00 2001 From: Yingjian Wu Date: Fri, 8 Mar 2024 12:02:22 -0500 Subject: [PATCH 4/4] add test --- .../groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy index 4eb68be97..ebd804053 100644 --- a/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy +++ b/metacat-functional-tests/src/functionalTest/groovy/com/netflix/metacat/MySqlLookupServiceSpec.groovy @@ -57,7 +57,7 @@ class MySqlLookupServiceSpec extends Specification{ expect: lookup.values.size() == expectedSize - lookup.values() == mySqlLookupService.getValues("mock") + lookup.values == mySqlLookupService.getValues("mock") where: valuesList | expectedSize