TabbedPaneNetworkTab.java

1
package com.jsql.view.swing.panel.consoles;
2
3
import com.jsql.model.bean.util.HttpHeader;
4
import com.jsql.util.I18nUtil;
5
import com.jsql.util.LogLevelUtil;
6
import com.jsql.util.StringUtil;
7
import com.jsql.view.swing.panel.util.HTMLEditorKitTextPaneWrap;
8
import com.jsql.view.swing.scrollpane.LightScrollPane;
9
import com.jsql.view.swing.tab.TabbedPaneWheeled;
10
import com.jsql.view.swing.text.JPopupTextArea;
11
import com.jsql.view.swing.text.JTextPanePlaceholder;
12
import com.jsql.view.swing.util.I18nViewUtil;
13
import org.apache.commons.lang3.StringUtils;
14
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
16
import org.jsoup.Jsoup;
17
import org.jsoup.safety.Safelist;
18
19
import javax.swing.*;
20
import javax.swing.text.DefaultCaret;
21
import java.util.AbstractMap.SimpleEntry;
22
import java.util.stream.Stream;
23
24
public class TabbedPaneNetworkTab extends TabbedPaneWheeled {
25
    
26
    /**
27
     * Log4j logger sent to view.
28
     */
29
    private static final Logger LOGGER = LogManager.getRootLogger();
30
31
    private final JTextArea textAreaNetworkTabUrl = new JPopupTextArea("Request URL").getProxy();
32
    private final JTextArea textAreaNetworkTabResponse = new JPopupTextArea("Response headers").getProxy();
33
    private final JTextArea textAreaNetworkTabSource = new JPopupTextArea("Page source").getProxy();
34
    private final JTextPane textAreaNetworkTabPreview = new JTextPanePlaceholder("Page rendering");
35
    private final JTextArea textAreaNetworkTabHeader = new JPopupTextArea("Request headers").getProxy();
36
    private final JTextArea textAreaNetworkTabParams = new JPopupTextArea("Request body").getProxy();
37
    
38
    public TabbedPaneNetworkTab() {
39
40 1 1. <init> : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::setName → NO_COVERAGE
        this.setName("tabNetwork");
41
        
42
        Stream.of(
43
            new SimpleEntry<>("NETWORK_TAB_URL_LABEL", this.textAreaNetworkTabUrl),
44
            new SimpleEntry<>("NETWORK_TAB_HEADERS_LABEL", this.textAreaNetworkTabHeader),
45
            new SimpleEntry<>("NETWORK_TAB_PARAMS_LABEL", this.textAreaNetworkTabParams),
46
            new SimpleEntry<>("NETWORK_TAB_RESPONSE_LABEL", this.textAreaNetworkTabResponse),
47
            new SimpleEntry<>("NETWORK_TAB_SOURCE_LABEL", this.textAreaNetworkTabSource),
48
            new SimpleEntry<>("NETWORK_TAB_PREVIEW_LABEL", this.textAreaNetworkTabPreview)
49
        )
50 1 1. <init> : removed call to java/util/stream/Stream::forEach → NO_COVERAGE
        .forEach(entry -> {
51
            
52 1 1. lambda$new$0 : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::addTab → NO_COVERAGE
            this.addTab(I18nUtil.valueByKey(entry.getKey()), new LightScrollPane(1, 1, 0, 0, entry.getValue()));
53
            var label = new JLabel(I18nUtil.valueByKey(entry.getKey()));
54 1 1. lambda$new$0 : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::setTabComponentAt → NO_COVERAGE
            this.setTabComponentAt(
55
                this.indexOfTab(I18nUtil.valueByKey(entry.getKey())),
56
                label
57
            );
58 1 1. lambda$new$0 : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
            I18nViewUtil.addComponentForKey(entry.getKey(), label);
59
            
60 1 1. lambda$new$0 : removed call to javax/swing/JLabel::setName → NO_COVERAGE
            label.setName("label"+ entry.getKey());
61 1 1. lambda$new$0 : removed call to javax/swing/text/JTextComponent::setName → NO_COVERAGE
            entry.getValue().setName("text"+ entry.getKey());
62
            
63
            DefaultCaret caret = (DefaultCaret) entry.getValue().getCaret();
64 1 1. lambda$new$0 : removed call to javax/swing/text/DefaultCaret::setUpdatePolicy → NO_COVERAGE
            caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
65
        });
66
        
67 1 1. <init> : removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE
        this.textAreaNetworkTabHeader.setLineWrap(true);
68 1 1. <init> : removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE
        this.textAreaNetworkTabParams.setLineWrap(true);
69 1 1. <init> : removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE
        this.textAreaNetworkTabResponse.setLineWrap(true);
70 1 1. <init> : removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE
        this.textAreaNetworkTabUrl.setLineWrap(true);
71 1 1. <init> : removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE
        this.textAreaNetworkTabSource.setLineWrap(true);
72
        
73 1 1. <init> : removed call to javax/swing/JTextPane::setEditorKit → NO_COVERAGE
        this.textAreaNetworkTabPreview.setEditorKit(new HTMLEditorKitTextPaneWrap());
74 1 1. <init> : removed call to javax/swing/JTextPane::setContentType → NO_COVERAGE
        this.textAreaNetworkTabPreview.setContentType("text/html");
75 1 1. <init> : removed call to javax/swing/JTextPane::setEditable → NO_COVERAGE
        this.textAreaNetworkTabPreview.setEditable(false);
76
    }
77
    
78
    public void changeTextNetwork(HttpHeader networkData) {
79
        
80 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabParams.setText(networkData.getPost());
81 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabUrl.setText(networkData.getUrl());
82
        
83 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabHeader.setText(StringUtils.EMPTY);
84 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabResponse.setText(StringUtils.EMPTY);
85
        
86 1 1. changeTextNetwork : negated conditional → NO_COVERAGE
        if (networkData.getHeader() != null) {
87
            
88
            for (String key: networkData.getHeader().keySet()) {
89
                
90 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::append → NO_COVERAGE
                this.textAreaNetworkTabHeader.append(key + ": " + networkData.getHeader().get(key));
91 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::append → NO_COVERAGE
                this.textAreaNetworkTabHeader.append("\n");
92
            }
93
        }
94
        
95 1 1. changeTextNetwork : negated conditional → NO_COVERAGE
        if (networkData.getResponse() != null) {
96
            
97
            for (String key: networkData.getResponse().keySet()) {
98
                
99 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::append → NO_COVERAGE
                this.textAreaNetworkTabResponse.append(key + ": " + networkData.getResponse().get(key));
100 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::append → NO_COVERAGE
                this.textAreaNetworkTabResponse.append("\n");
101
            }
102
        }
103
        
104
        // Fix #53736: ArrayIndexOutOfBoundsException on setText()
105
        // Fix #54573: NullPointerException on setText()
106
        try {
107 1 1. changeTextNetwork : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
            this.textAreaNetworkTabSource.setText(
108
                StringUtil
109
                .detectUtf8(networkData.getSource())
110
                .replaceAll("#{5,}", "#*")
111
                .trim()
112
            );
113
        } catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
114
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
115
        }
116
        
117
        // Reset EditorKit to disable previous document effect
118
        this.textAreaNetworkTabPreview.getEditorKit().createDefaultDocument();
119
        
120
        // Proxy is used by jsoup to display <img> tags
121
        // Previous test for 2xx Success and 3xx Redirection was Header only,
122
        // now get the HTML content
123
        // Fix #35352: EmptyStackException on setText()
124
        // Fix #39841: RuntimeException on setText()
125
        // Fix #42523: ExceptionInInitializerError on clean()
126
        try {
127 1 1. changeTextNetwork : removed call to javax/swing/JTextPane::setText → NO_COVERAGE
            this.textAreaNetworkTabPreview.setText(
128
                Jsoup.clean(
129
                    String.format(
130
                        "<html>%s</html>",
131
                        StringUtil.detectUtf8(networkData.getSource())
132
                    )
133
                    .replaceAll(
134
                        "<img[^>]*>",
135
                        StringUtils.EMPTY
136
                    )
137
                    .replaceAll(
138
                        "<input[^>]*type=\"?hidden\"?.*>",
139
                        StringUtils.EMPTY
140
                    )
141
                    .replaceAll(
142
                        "<input[^>]*type=\"?(submit|button)\"?.*>",
143
                        "<div style=\"background-color:#eeeeee;text-align:center;border:1px solid black;width:100px;\">button</div>"
144
                    )
145
                    .replaceAll(
146
                        "<input[^>]*>",
147
                        "<div style=\"text-align:center;border:1px solid black;width:100px;\">input</div>"
148
                    ),
149
                    Safelist.relaxed()
150
                        .addTags("center", "div", "span")
151
                        .addAttributes(":all", "style")
152
                )
153
            );
154
        } catch (Exception | ExceptionInInitializerError e) {
155
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
156
        }
157
    }
158
    
159
    public void reset() {
160
        
161 1 1. reset : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabUrl.setText(StringUtils.EMPTY);
162 1 1. reset : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabHeader.setText(StringUtils.EMPTY);
163 1 1. reset : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabParams.setText(StringUtils.EMPTY);
164 1 1. reset : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textAreaNetworkTabResponse.setText(StringUtils.EMPTY);
165
        
166
        // Fix #54572: NullPointerException on setText()
167
        try {
168 1 1. reset : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
            this.textAreaNetworkTabSource.setText(StringUtils.EMPTY);
169
        } catch (NullPointerException e) {
170
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
171
        }
172
        
173
        // Fix #41879: ArrayIndexOutOfBoundsException on setText()
174
        try {
175 1 1. reset : removed call to javax/swing/JTextPane::setText → NO_COVERAGE
            this.textAreaNetworkTabPreview.setText(StringUtils.EMPTY);
176
        } catch (ArrayIndexOutOfBoundsException e) {
177
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
178
        }
179
    }
180
}

Mutations

40

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::setName → NO_COVERAGE

50

1.1
Location : <init>
Killed by : none
removed call to java/util/stream/Stream::forEach → NO_COVERAGE

52

1.1
Location : lambda$new$0
Killed by : none
removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::addTab → NO_COVERAGE

54

1.1
Location : lambda$new$0
Killed by : none
removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::setTabComponentAt → NO_COVERAGE

58

1.1
Location : lambda$new$0
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

60

1.1
Location : lambda$new$0
Killed by : none
removed call to javax/swing/JLabel::setName → NO_COVERAGE

61

1.1
Location : lambda$new$0
Killed by : none
removed call to javax/swing/text/JTextComponent::setName → NO_COVERAGE

64

1.1
Location : lambda$new$0
Killed by : none
removed call to javax/swing/text/DefaultCaret::setUpdatePolicy → NO_COVERAGE

67

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE

68

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE

69

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE

70

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE

71

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE

73

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextPane::setEditorKit → NO_COVERAGE

74

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextPane::setContentType → NO_COVERAGE

75

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTextPane::setEditable → NO_COVERAGE

80

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

81

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

83

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

84

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

86

1.1
Location : changeTextNetwork
Killed by : none
negated conditional → NO_COVERAGE

90

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::append → NO_COVERAGE

91

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::append → NO_COVERAGE

95

1.1
Location : changeTextNetwork
Killed by : none
negated conditional → NO_COVERAGE

99

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::append → NO_COVERAGE

100

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::append → NO_COVERAGE

107

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

127

1.1
Location : changeTextNetwork
Killed by : none
removed call to javax/swing/JTextPane::setText → NO_COVERAGE

161

1.1
Location : reset
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

162

1.1
Location : reset
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

163

1.1
Location : reset
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

164

1.1
Location : reset
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

168

1.1
Location : reset
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

175

1.1
Location : reset
Killed by : none
removed call to javax/swing/JTextPane::setText → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1