Skip to content

Commit

Permalink
write a line into test.file
Browse files Browse the repository at this point in the history
  • Loading branch information
huifer committed Nov 25, 2023
1 parent e797804 commit 369c01e
Show file tree
Hide file tree
Showing 13 changed files with 1,291 additions and 0 deletions.
709 changes: 709 additions & 0 deletions docs/spring/cs3b526262-8b50-11ee-a01d-acde48001122.java

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions docs/spring/cs3b98f240-8b50-11ee-a01d-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.huifer.jdk.jdk8.stearm;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* 描述:
*
* @author huifer
* @date 2019-06-16
*/
public class Demo03 {
public static void main(String[] args) {
Stream<String> stringStream = Stream.of("a", "b", "c");
ArrayList<String> collect = stringStream.collect(Collectors.toCollection(ArrayList::new));
HashSet<String> collect1 = stringStream.collect(Collectors.toCollection(HashSet::new));
}
}
198 changes: 198 additions & 0 deletions docs/spring/cs3bdc328a-8b50-11ee-a01d-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/**
* Copyright 2009-2019 the original author or authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 org.apache.ibatis.type;

import org.apache.ibatis.BaseDataTest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.testcontainers.PgContainer;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

import java.sql.Connection;
import java.sql.SQLXML;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@Tag("TestcontainersTests")
class SqlxmlTypeHandlerTest extends BaseTypeHandlerTest {
private static final TypeHandler<String> TYPE_HANDLER = new SqlxmlTypeHandler();

private static SqlSessionFactory sqlSessionFactory;

@Mock
private SQLXML sqlxml;

@Mock
private Connection connection;

@BeforeAll
static void setUp() throws Exception {
Configuration configuration = new Configuration();
Environment environment = new Environment("development", new JdbcTransactionFactory(),
PgContainer.getUnpooledDataSource());
configuration.setEnvironment(environment);
configuration.addMapper(Mapper.class);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);

BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
"org/apache/ibatis/type/SqlxmlTypeHandlerTest.sql");
}

@Override
@Test
public void shouldSetParameter() throws Exception {
when(connection.createSQLXML()).thenReturn(sqlxml);
when(ps.getConnection()).thenReturn(connection);
String xml = "<message>test</message>";
TYPE_HANDLER.setParameter(ps, 1, xml, null);
verify(ps).setSQLXML(1, sqlxml);
verify(sqlxml).setString(xml);
verify(sqlxml).free();
}

@Override
@Test
public void shouldGetResultFromResultSetByName() throws Exception {
String xml = "<message>test</message>";
when(sqlxml.getString()).thenReturn(xml);
when(rs.getSQLXML("column")).thenReturn(sqlxml);
assertEquals(xml, TYPE_HANDLER.getResult(rs, "column"));
verify(sqlxml).free();
}

@Override
@Test
public void shouldGetResultNullFromResultSetByName() throws Exception {
when(rs.getSQLXML("column")).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(rs, "column"));
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
String xml = "<message>test</message>";
when(sqlxml.getString()).thenReturn(xml);
when(rs.getSQLXML(1)).thenReturn(sqlxml);
assertEquals(xml, TYPE_HANDLER.getResult(rs, 1));
verify(sqlxml).free();
}

@Override
@Test
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
when(rs.getSQLXML(1)).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(rs, 1));
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
String xml = "<message>test</message>";
when(sqlxml.getString()).thenReturn(xml);
when(cs.getSQLXML(1)).thenReturn(sqlxml);
assertEquals(xml, TYPE_HANDLER.getResult(cs, 1));
verify(sqlxml).free();
}

@Override
@Test
public void shouldGetResultNullFromCallableStatement() throws Exception {
when(cs.getSQLXML(1)).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(cs, 1));
}

@Test
void shouldReturnXmlAsString() {
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = mapper.select(1);
assertEquals("<title>XML data</title>",
bean.getContent());
}
}

@Test
void shouldReturnNull() {
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = mapper.select(2);
assertNull(bean.getContent());
}
}

@Test
void shouldInsertXmlString() {
final Integer id = 100;
final String content = "<books><book><title>Save XML</title></book><book><title>Get XML</title></book></books>";
// Insert
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = new XmlBean();
bean.setId(id);
bean.setContent(content);
mapper.insert(bean);
session.commit();
}
// Select to verify
try (SqlSession session = sqlSessionFactory.openSession()) {
Mapper mapper = session.getMapper(Mapper.class);
XmlBean bean = mapper.select(id);
assertEquals(content, bean.getContent());
}
}

interface Mapper {
@Select("select id, content from mbtest.test_sqlxml where id = #{id}")
XmlBean select(Integer id);

@Insert("insert into mbtest.test_sqlxml (id, content) values (#{id}, #{content,jdbcType=SQLXML})")
void insert(XmlBean bean);
}

public static class XmlBean {
private Integer id;

private String content;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}
}
}
49 changes: 49 additions & 0 deletions docs/spring/cs3c21dcc2-8b50-11ee-a01d-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2009-2019 the original author or authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 org.apache.ibatis.testcontainers;

import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
import org.testcontainers.containers.PostgreSQLContainer;

import javax.sql.DataSource;

public class PgContainer {

private static final String DB_NAME = "mybatis_test";
private static final String USERNAME = "u";
private static final String PASSWORD = "p";
private static final String DRIVER = "org.postgresql.Driver";

private static final PostgreSQLContainer<?> INSTANCE = initContainer();

private PgContainer() {
super();
}

private static PostgreSQLContainer<?> initContainer() {
@SuppressWarnings("resource")
PostgreSQLContainer<?> container = new PostgreSQLContainer<>().withDatabaseName(DB_NAME).withUsername(USERNAME)
.withPassword(PASSWORD);
container.start();
return container;
}

public static DataSource getUnpooledDataSource() {
return new UnpooledDataSource(PgContainer.DRIVER, INSTANCE.getJdbcUrl(), PgContainer.USERNAME,
PgContainer.PASSWORD);
}
}
8 changes: 8 additions & 0 deletions docs/spring/cs3c6388c0-8b50-11ee-a01d-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.huifer.tuc.service;

public interface CompanyService {

void syncCompanySubUser();


}
25 changes: 25 additions & 0 deletions docs/spring/cs3ca4a706-8b50-11ee-a01d-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.huifer.idgen.my.service.conv;

import com.huifer.idgen.my.service.bean.Id;

/**
* @author: wang
* @description: IdConverter
*/
public interface IdConverter {

/**
* {@link Id 转换成longid}
*
* @param id id
*/
long converter(Id id);

/**
* long id 转换成 {@link Id}
*
* @param id longId
*/
Id converter(long id);

}
29 changes: 29 additions & 0 deletions docs/spring/cs3ce65d54-8b50-11ee-a01d-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.huifer.zk.rpcclient;

import com.huifer.zk.zkfind.ZkServerDiscovery;

import java.lang.reflect.Proxy;

/**
* <p>Title : ZkRpcClient </p>
* <p>Description : </p>
*
* @author huifer
* @date 2019-06-13
*/
public class ZkRpcClient {

private ZkServerDiscovery discovery;

public ZkRpcClient(ZkServerDiscovery discovery) {
this.discovery = discovery;
}

public <T> T clientProxy(final Class<T> interfaceCls) {

return (T) Proxy.newProxyInstance(interfaceCls.getClassLoader(),
new Class[]{interfaceCls}, new ZkInvocationHandler(discovery));

}

}
12 changes: 12 additions & 0 deletions docs/spring/cs3d27d644-8b50-11ee-a01d-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.huifer.design.decorate.cake;

public abstract class BaseCake {

protected String msg() {
return "蛋糕";
}

protected int price() {
return 10;
}
}
Loading

0 comments on commit 369c01e

Please sign in to comment.