Search in sources :

Example 61 with Consumer

use of java.util.function.Consumer in project pact-jvm by DiUS.

the class HttpTarget method getProviderInfo.

protected ProviderInfo getProviderInfo() {
    Provider provider = testClass.getAnnotation(Provider.class);
    final ProviderInfo providerInfo = new ProviderInfo(provider.value());
    providerInfo.setPort(port);
    providerInfo.setHost(host);
    providerInfo.setProtocol(protocol);
    providerInfo.setPath(path);
    providerInfo.setInsecure(insecure);
    if (testClass != null) {
        final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
        if (!methods.isEmpty()) {
            providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
                try {
                    method.invokeExplosively(testTarget, httpRequest);
                } catch (Throwable t) {
                    throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
                }
            }));
        }
    }
    return providerInfo;
}
Also used : HttpRequest(org.apache.http.HttpRequest) SystemPropertyResolver(au.com.dius.pact.provider.junit.sysprops.SystemPropertyResolver) FrameworkMethod(org.junit.runners.model.FrameworkMethod) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ValueResolver(au.com.dius.pact.provider.junit.sysprops.ValueResolver) URL(java.net.URL) HashMap(java.util.HashMap) Interaction(au.com.dius.pact.model.Interaction) Provider(au.com.dius.pact.provider.junit.Provider) HttpRequest(org.apache.http.HttpRequest) Consumer(java.util.function.Consumer) List(java.util.List) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) TestClass(org.junit.runners.model.TestClass) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) Map(java.util.Map) TargetRequestFilter(au.com.dius.pact.provider.junit.TargetRequestFilter) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Provider(au.com.dius.pact.provider.junit.Provider)

Example 62 with Consumer

use of java.util.function.Consumer in project pact-jvm by DiUS.

the class MockMvcTarget method getProviderInfo.

@Override
protected ProviderInfo getProviderInfo() {
    Provider provider = testClass.getAnnotation(Provider.class);
    final ProviderInfo providerInfo = new ProviderInfo(provider.value());
    if (testClass != null) {
        final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
        if (!methods.isEmpty()) {
            providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
                try {
                    method.invokeExplosively(testTarget, httpRequest);
                } catch (Throwable t) {
                    throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
                }
            }));
        }
    }
    return providerInfo;
}
Also used : HttpRequest(org.apache.http.HttpRequest) java.util(java.util) FrameworkMethod(org.junit.runners.model.FrameworkMethod) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) MethodClosure(org.codehaus.groovy.runtime.MethodClosure) URL(java.net.URL) MvcProviderVerifier(au.com.dius.pact.provider.spring.MvcProviderVerifier) MockMvcBuilders.standaloneSetup(org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup) PactVerification(au.com.dius.pact.provider.PactVerification) BaseTarget(au.com.dius.pact.provider.junit.target.BaseTarget) Interaction(au.com.dius.pact.model.Interaction) Provider(au.com.dius.pact.provider.junit.Provider) HttpRequest(org.apache.http.HttpRequest) MockMvc(org.springframework.test.web.servlet.MockMvc) Consumer(java.util.function.Consumer) URLClassLoader(java.net.URLClassLoader) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) RequestResponseInteraction(au.com.dius.pact.model.RequestResponseInteraction) TargetRequestFilter(au.com.dius.pact.provider.junit.TargetRequestFilter) Target(au.com.dius.pact.provider.junit.target.Target) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Provider(au.com.dius.pact.provider.junit.Provider)

Example 63 with Consumer

use of java.util.function.Consumer in project Gargoyle by callakrsos.

the class CrudBaseGridView method saveBtnClickHandler.

/**
	 * 저장버튼 클릭 핸들러
	 *
	 * @param saveClickCallbackProperty2
	 *
	 * @Date 2015. 10. 10.
	 * @return
	 * @User KYJ
	 */
private EventHandler<MouseEvent> saveBtnClickHandler(ObjectProperty<Consumer<List<T>>> saveClickCallbackProperty) {
    return new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            try {
                Consumer<List<T>> callback = saveClickCallbackProperty.get();
                if (callback == null) {
                    errorMsgCallback.accept("saveClickCallback 함수에 에러메세지 콜백을 등록하세요.");
                    return;
                }
                gridview.fireEvent(event);
                List<T> items = getItems();
                //필수값 검증로직 추가. 2016.12.08
                AbstractVoNullChecker<T> nullCheckHandler = new DefaultVoNullChecker<>(CrudBaseGridView.this);
                nullCheckHandler.setList(items);
                Optional<Field> findFirst = nullCheckHandler.findFirst();
                boolean present = findFirst.isPresent();
                if (present) {
                    String msgFieldName = nullCheckHandler.getMsgNameByfield();
                    //						String message = ValueUtil.getMessage("MSG_W_000001", msgFieldName);
                    int emptyIndex = nullCheckHandler.getEmptyIndex();
                    Set<Node> findAllByNodes = CrudBaseGridView.this.lookupAll("TableRow");
                    findAllByNodes.stream().map(n -> (TableRow) n).filter(r -> {
                        return emptyIndex == r.getIndex();
                    }).findFirst().ifPresent(n -> {
                        Timeline timeline = new Timeline();
                        timeline.setCycleCount(10);
                        timeline.setAutoReverse(true);
                        KeyFrame keyFrame = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px"));
                        KeyFrame keyFrame2 = new KeyFrame(Duration.millis(500), new KeyValue(n.styleProperty(), ""));
                        KeyValue keyValueX = new KeyValue(n.styleProperty(), "-fx-border-color : red ; -fx-border-width : 1px");
                        KeyValue keyValueY = new KeyValue(n.styleProperty(), "");
                        KeyFrame keyFrame3 = new KeyFrame(Duration.seconds(2), "", keyValueX, keyValueY);
                        timeline.getKeyFrames().add(keyFrame3);
                        timeline.play();
                    });
                    getSelectionModel().select(emptyIndex);
                    //						DialogUtil.showMessageDialog(SharedMemory.getPrimaryStage(), msgFieldName + " Field is empty.");
                    return;
                }
                List<T> arrayList = new ArrayList<T>(items);
                arrayList.addAll(deleteItems);
                callback.accept(arrayList);
                // 사용자 정의 로직이 이상없으면 deleteItems 항목도 비운다.
                deleteItems.clear();
            } catch (Exception e) {
                throw e;
            }
        }
    };
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) MouseEvent(javafx.scene.input.MouseEvent) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Insets(javafx.geometry.Insets) KeyValue(javafx.animation.KeyValue) HBox(javafx.scene.layout.HBox) KeyFrame(javafx.animation.KeyFrame) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Node(javafx.scene.Node) TableRow(javafx.scene.control.TableRow) Set(java.util.Set) Timeline(javafx.animation.Timeline) Field(java.lang.reflect.Field) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) ActionEvent(javafx.event.ActionEvent) Duration(javafx.util.Duration) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) MouseEvent(javafx.scene.input.MouseEvent) KeyValue(javafx.animation.KeyValue) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) EventHandler(javafx.event.EventHandler) Field(java.lang.reflect.Field) Timeline(javafx.animation.Timeline) TableRow(javafx.scene.control.TableRow) KeyFrame(javafx.animation.KeyFrame) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList)

Example 64 with Consumer

use of java.util.function.Consumer in project Gargoyle by callakrsos.

the class CommonsSqllPan method queryAll.

/**
	 * @inheritDoc
	 */
@Override
public void queryAll(List<String> queryArray, Consumer<Integer> onSuccess, BiConsumer<Exception, Boolean> exceptionHandler) {
    int result = -1;
    Connection con = null;
    try {
        con = connectionSupplier.get();
        // List<List<String>> collect = Stream.of(queryArray).filter(str ->
        // ValueUtil.isNotEmpty(str)).map(str ->
        // str).collect(Collectors.toList());
        result = DbUtil.getTransactionedScope(con, queryArray, arr -> {
            List<String> collect = arr.stream().filter(str -> ValueUtil.isNotEmpty(str)).collect(Collectors.toList());
            return collect;
        }, ex -> {
            LOGGER.error(ValueUtil.toString(ex));
            exceptionHandler.accept(ex, true);
        });
        onSuccess.accept(result);
    } catch (SQLException e) {
        boolean showDialog = true;
        // 사용자가 SQL을 잘못입력한경우 처리할 내용. [크리틱컬하지않는 에러... 처리.]
        if ("42P01".equals(e.getSQLState())) {
            LOGGER.error(ValueUtil.toString(e));
            showDialog = false;
        } else if ("42S02".equals(e.getSQLState())) {
            LOGGER.error(ValueUtil.toString(e));
            showDialog = false;
        } else /* Postgre sql */
        if ("42601".equals(e.getSQLState())) {
            LOGGER.error(ValueUtil.toString(e));
            showDialog = false;
        }
        exceptionHandler.accept(e, showDialog);
    } catch (Exception e) {
        LOGGER.error(ValueUtil.toString(e));
        exceptionHandler.accept(e, true);
    } finally /* 2015.11.12 finnaly문 추가. */
    {
        try {
            if (con != null)
                con.close();
        } catch (SQLException e) {
            LOGGER.error(ValueUtil.toString(e));
        }
    }
}
Also used : Connection(java.sql.Connection) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) SchemaItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.SchemaItemTree) Map(java.util.Map) ColumnItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.ColumnItemTree) TableInformationUserMetadataVO(com.kyj.fx.voeditor.visual.component.sql.table.TableInformationUserMetadataVO) Pair(javafx.util.Pair) DatabaseTreeNode(com.kyj.fx.voeditor.visual.component.sql.dbtree.DatabaseTreeNode) Set(java.util.Set) KeyEvent(javafx.scene.input.KeyEvent) SimpleTextView(com.kyj.fx.voeditor.visual.component.text.SimpleTextView) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) TableInformationFrameView(com.kyj.fx.voeditor.visual.component.sql.table.TableInformationFrameView) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) ResourceLoader(com.kyj.fx.voeditor.visual.momory.ResourceLoader) DatabaseItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) Scene(javafx.scene.Scene) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException) ResultSetToMapConverter(com.kyj.fx.voeditor.visual.functions.ResultSetToMapConverter) TreeItem(javafx.scene.control.TreeItem) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) TableItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.TableItemTree) BiConsumer(java.util.function.BiConsumer) KeyCode(javafx.scene.input.KeyCode) Properties(java.util.Properties) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FxClipboardUtil(com.kyj.fx.voeditor.visual.util.FxClipboardUtil) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) GagoyleParamEmptyException(com.kyj.fx.voeditor.visual.exceptions.GagoyleParamEmptyException) Consumer(java.util.function.Consumer) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) NotYetSupportException(com.kyj.fx.voeditor.visual.exceptions.NotYetSupportException) DatabaseTreeCallback(com.kyj.fx.voeditor.visual.component.sql.dbtree.DatabaseTreeCallback) Collections(java.util.Collections) SQLException(java.sql.SQLException) Connection(java.sql.Connection) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException) SQLException(java.sql.SQLException) IOException(java.io.IOException) GagoyleParamEmptyException(com.kyj.fx.voeditor.visual.exceptions.GagoyleParamEmptyException) NotYetSupportException(com.kyj.fx.voeditor.visual.exceptions.NotYetSupportException)

Example 65 with Consumer

use of java.util.function.Consumer in project Gargoyle by callakrsos.

the class DbUtil method getTransactionedScope.

public static <T> int getTransactionedScope(Connection con, T userObj, Function<T, List<String>> sqlConverter, Consumer<Exception> exceptionHandler) throws Exception {
    int result = -1;
    try {
        LOGGER.debug("is AutoCommit ? : {}", con.getAutoCommit());
        con.setAutoCommit(false);
        List<String> apply = sqlConverter.apply(userObj);
        Statement createStatement = con.createStatement();
        for (String sql : apply) {
            /*
				 * sqlite에서 공백이 포함된 sql은 add한경우 에러.
				 * 확인해보니 isEmpty함수에 이상이 있는듯하여 수정.
				 */
            if (ValueUtil.isEmpty(sql))
                continue;
            LOGGER.debug(sql);
            createStatement.addBatch(sql);
        }
        int[] executeBatch = createStatement.executeBatch();
        con.commit();
        result = (int) IntStream.of(executeBatch).filter(v -> v == 0).count();
    } catch (Exception e) {
        con.rollback();
        exceptionHandler.accept(e);
        result = -1;
    } finally {
        con.commit();
        close(con);
    }
    return result;
}
Also used : IntStream(java.util.stream.IntStream) BiTransactionScope(com.kyj.fx.voeditor.visual.functions.BiTransactionScope) Arrays(java.util.Arrays) Connection(java.sql.Connection) ResultSetToMapConverter(com.kyj.fx.voeditor.visual.functions.ResultSetToMapConverter) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) DatabaseMetaData(java.sql.DatabaseMetaData) HashMap(java.util.HashMap) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) RowMapperResultSetExtractor(org.springframework.jdbc.core.RowMapperResultSetExtractor) Function(java.util.function.Function) Supplier(java.util.function.Supplier) PoolProperties(org.apache.tomcat.jdbc.pool.PoolProperties) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager) Map(java.util.Map) DataSource(org.apache.tomcat.jdbc.pool.DataSource) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) Properties(java.util.Properties) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ParameterizedBeanPropertyRowMapper(org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper) PreparedStatement(java.sql.PreparedStatement) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) Driver(java.sql.Driver) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Statement(java.sql.Statement) Entry(java.util.Map.Entry) RowMapper(org.springframework.jdbc.core.RowMapper) Optional(java.util.Optional) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException) Collections(java.util.Collections) DriverManager(java.sql.DriverManager) ResultSetMetaData(java.sql.ResultSetMetaData) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SQLException(java.sql.SQLException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException)

Aggregations

Consumer (java.util.function.Consumer)908 List (java.util.List)445 ArrayList (java.util.ArrayList)288 Test (org.junit.Test)250 Map (java.util.Map)228 IOException (java.io.IOException)223 Collectors (java.util.stream.Collectors)205 Collections (java.util.Collections)185 Arrays (java.util.Arrays)181 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)163 TimeUnit (java.util.concurrent.TimeUnit)157 HashMap (java.util.HashMap)152 Set (java.util.Set)149 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)146 Optional (java.util.Optional)132 Collection (java.util.Collection)127 Function (java.util.function.Function)119 CountDownLatch (java.util.concurrent.CountDownLatch)116 File (java.io.File)112 AtomicReference (java.util.concurrent.atomic.AtomicReference)111